| Line Number |
../DebugInfoTest/example_mips_dbg.ll
BUT NOT
../DebugInfoTest/example_mips.ll
|
Line Number |
../DebugInfoTest/example_mips.ll
BUT NOT
../DebugInfoTest/example_mips_dbg.ll
|
| 1 |
//===-- Verifier.cpp - Implement the Module Verifier -----------------------==// |
1 |
//===-- Verifier.cpp - Implement the Module Verifier -----------------------==// |
| 2 |
// |
2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
7 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
8 |
// |
| 9 |
// This file defines the function verifier interface, that can be used for some |
9 |
// This file defines the function verifier interface, that can be used for some |
| 10 |
// basic correctness checking of input to the system. |
10 |
// basic correctness checking of input to the system. |
| 11 |
// |
11 |
// |
| 12 |
// Note that this does not provide full `Java style' security and verifications, |
12 |
// Note that this does not provide full `Java style' security and verifications, |
| 13 |
// instead it just tries to ensure that code is well-formed. |
13 |
// instead it just tries to ensure that code is well-formed. |
| 14 |
// |
14 |
// |
| 15 |
// * Both of a binary operator's parameters are of the same type |
15 |
// * Both of a binary operator's parameters are of the same type |
| 16 |
// * Verify that the indices of mem access instructions match other operands |
16 |
// * Verify that the indices of mem access instructions match other operands |
| 17 |
// * Verify that arithmetic and other things are only performed on first-class |
17 |
// * Verify that arithmetic and other things are only performed on first-class |
| 18 |
// types. Verify that shifts & logicals only happen on integrals f.e. |
18 |
// types. Verify that shifts & logicals only happen on integrals f.e. |
| 19 |
// * All of the constants in a switch statement are of the correct type |
19 |
// * All of the constants in a switch statement are of the correct type |
| 20 |
// * The code is in valid SSA form |
20 |
// * The code is in valid SSA form |
| 21 |
// * It should be illegal to put a label into any other type (like a structure) |
21 |
// * It should be illegal to put a label into any other type (like a structure) |
| 22 |
// or to return one. [except constant arrays!] |
22 |
// or to return one. [except constant arrays!] |
| 23 |
// * Only phi nodes can be self referential: 'add i32 %0, %0 ; :0' is bad |
23 |
// * Only phi nodes can be self referential: 'add i32 %0, %0 ; :0' is bad |
| 24 |
// * PHI nodes must have an entry for each predecessor, with no extras. |
24 |
// * PHI nodes must have an entry for each predecessor, with no extras. |
| 25 |
// * PHI nodes must be the first thing in a basic block, all grouped together |
25 |
// * PHI nodes must be the first thing in a basic block, all grouped together |
| 26 |
// * All basic blocks should only end with terminator insts, not contain them |
26 |
// * All basic blocks should only end with terminator insts, not contain them |
| 27 |
// * The entry node to a function must not have predecessors |
27 |
// * The entry node to a function must not have predecessors |
| 28 |
// * All Instructions must be embedded into a basic block |
28 |
// * All Instructions must be embedded into a basic block |
| 29 |
// * Functions cannot take a void-typed parameter |
29 |
// * Functions cannot take a void-typed parameter |
| 30 |
// * Verify that a function's argument list agrees with it's declared type. |
30 |
// * Verify that a function's argument list agrees with it's declared type. |
| 31 |
// * It is illegal to specify a name for a void value. |
31 |
// * It is illegal to specify a name for a void value. |
| 32 |
// * It is illegal to have a internal global value with no initializer |
32 |
// * It is illegal to have a internal global value with no initializer |
| 33 |
// * It is illegal to have a ret instruction that returns a value that does not |
33 |
// * It is illegal to have a ret instruction that returns a value that does not |
| 34 |
// agree with the function return value type. |
34 |
// agree with the function return value type. |
| 35 |
// * Function call argument types match the function prototype |
35 |
// * Function call argument types match the function prototype |
| 36 |
// * A landing pad is defined by a landingpad instruction, and can be jumped to |
36 |
// * A landing pad is defined by a landingpad instruction, and can be jumped to |
| 37 |
// only by the unwind edge of an invoke instruction. |
37 |
// only by the unwind edge of an invoke instruction. |
| 38 |
// * A landingpad instruction must be the first non-PHI instruction in the |
38 |
// * A landingpad instruction must be the first non-PHI instruction in the |
| 39 |
// block. |
39 |
// block. |
| 40 |
// * Landingpad instructions must be in a function with a personality function. |
40 |
// * Landingpad instructions must be in a function with a personality function. |
| 41 |
// * Convergence control intrinsics are introduced in ConvergentOperations.rst. |
41 |
// * Convergence control intrinsics are introduced in ConvergentOperations.rst. |
| 42 |
// The applied restrictions are too numerous to list here. |
42 |
// The applied restrictions are too numerous to list here. |
| 43 |
// * The convergence entry intrinsic and the loop heart must be the first |
43 |
// * The convergence entry intrinsic and the loop heart must be the first |
| 44 |
// non-PHI instruction in their respective block. This does not conflict with |
44 |
// non-PHI instruction in their respective block. This does not conflict with |
| 45 |
// the landing pads, since these two kinds cannot occur in the same block. |
45 |
// the landing pads, since these two kinds cannot occur in the same block. |
| 46 |
// * All other things that are tested by asserts spread about the code... |
46 |
// * All other things that are tested by asserts spread about the code... |
| 47 |
// |
47 |
// |
| 48 |
//===----------------------------------------------------------------------===// |
48 |
//===----------------------------------------------------------------------===// |
| 49 |
|
49 |
|
| 50 |
#include "llvm/IR/Verifier.h" |
50 |
#include "llvm/IR/Verifier.h" |
| 51 |
#include "llvm/ADT/APFloat.h" |
51 |
#include "llvm/ADT/APFloat.h" |
| 52 |
#include "llvm/ADT/APInt.h" |
52 |
#include "llvm/ADT/APInt.h" |
| 53 |
#include "llvm/ADT/ArrayRef.h" |
53 |
#include "llvm/ADT/ArrayRef.h" |
| 54 |
#include "llvm/ADT/DenseMap.h" |
54 |
#include "llvm/ADT/DenseMap.h" |
| 55 |
#include "llvm/ADT/MapVector.h" |
55 |
#include "llvm/ADT/MapVector.h" |
| 56 |
#include "llvm/ADT/PostOrderIterator.h" |
56 |
#include "llvm/ADT/PostOrderIterator.h" |
| 57 |
#include "llvm/ADT/STLExtras.h" |
57 |
#include "llvm/ADT/STLExtras.h" |
| 58 |
#include "llvm/ADT/SmallPtrSet.h" |
58 |
#include "llvm/ADT/SmallPtrSet.h" |
| 59 |
#include "llvm/ADT/SmallSet.h" |
59 |
#include "llvm/ADT/SmallSet.h" |
| 60 |
#include "llvm/ADT/SmallVector.h" |
60 |
#include "llvm/ADT/SmallVector.h" |
| 61 |
#include "llvm/ADT/StringExtras.h" |
61 |
#include "llvm/ADT/StringExtras.h" |
| 62 |
#include "llvm/ADT/StringMap.h" |
62 |
#include "llvm/ADT/StringMap.h" |
| 63 |
#include "llvm/ADT/StringRef.h" |
63 |
#include "llvm/ADT/StringRef.h" |
| 64 |
#include "llvm/ADT/Twine.h" |
64 |
#include "llvm/ADT/Twine.h" |
| 65 |
#include "llvm/BinaryFormat/Dwarf.h" |
65 |
#include "llvm/BinaryFormat/Dwarf.h" |
| 66 |
#include "llvm/IR/Argument.h" |
66 |
#include "llvm/IR/Argument.h" |
| 67 |
#include "llvm/IR/AttributeMask.h" |
67 |
#include "llvm/IR/AttributeMask.h" |
| 68 |
#include "llvm/IR/Attributes.h" |
68 |
#include "llvm/IR/Attributes.h" |
| 69 |
#include "llvm/IR/BasicBlock.h" |
69 |
#include "llvm/IR/BasicBlock.h" |
| 70 |
#include "llvm/IR/CFG.h" |
70 |
#include "llvm/IR/CFG.h" |
| 71 |
#include "llvm/IR/CallingConv.h" |
71 |
#include "llvm/IR/CallingConv.h" |
| 72 |
#include "llvm/IR/Comdat.h" |
72 |
#include "llvm/IR/Comdat.h" |
| 73 |
#include "llvm/IR/Constant.h" |
73 |
#include "llvm/IR/Constant.h" |
| 74 |
#include "llvm/IR/ConstantRange.h" |
74 |
#include "llvm/IR/ConstantRange.h" |
| 75 |
#include "llvm/IR/Constants.h" |
75 |
#include "llvm/IR/Constants.h" |
| 76 |
#include "llvm/IR/CycleInfo.h" |
76 |
#include "llvm/IR/CycleInfo.h" |
| 77 |
#include "llvm/IR/DataLayout.h" |
77 |
#include "llvm/IR/DataLayout.h" |
| 78 |
#include "llvm/IR/DebugInfo.h" |
78 |
#include "llvm/IR/DebugInfo.h" |
| 79 |
#include "llvm/IR/DebugInfoMetadata.h" |
79 |
#include "llvm/IR/DebugInfoMetadata.h" |
| 80 |
#include "llvm/IR/DebugLoc.h" |
80 |
#include "llvm/IR/DebugLoc.h" |
| 81 |
#include "llvm/IR/DerivedTypes.h" |
81 |
#include "llvm/IR/DerivedTypes.h" |
| 82 |
#include "llvm/IR/Dominators.h" |
82 |
#include "llvm/IR/Dominators.h" |
| 83 |
#include "llvm/IR/EHPersonalities.h" |
83 |
#include "llvm/IR/EHPersonalities.h" |
| 84 |
#include "llvm/IR/Function.h" |
84 |
#include "llvm/IR/Function.h" |
| 85 |
#include "llvm/IR/GCStrategy.h" |
85 |
#include "llvm/IR/GCStrategy.h" |
| 86 |
#include "llvm/IR/GlobalAlias.h" |
86 |
#include "llvm/IR/GlobalAlias.h" |
| 87 |
#include "llvm/IR/GlobalValue.h" |
87 |
#include "llvm/IR/GlobalValue.h" |
| 88 |
#include "llvm/IR/GlobalVariable.h" |
88 |
#include "llvm/IR/GlobalVariable.h" |
| 89 |
#include "llvm/IR/InlineAsm.h" |
89 |
#include "llvm/IR/InlineAsm.h" |
| 90 |
#include "llvm/IR/InstVisitor.h" |
90 |
#include "llvm/IR/InstVisitor.h" |
| 91 |
#include "llvm/IR/InstrTypes.h" |
91 |
#include "llvm/IR/InstrTypes.h" |
| 92 |
#include "llvm/IR/Instruction.h" |
92 |
#include "llvm/IR/Instruction.h" |
| 93 |
#include "llvm/IR/Instructions.h" |
93 |
#include "llvm/IR/Instructions.h" |
| 94 |
#include "llvm/IR/IntrinsicInst.h" |
94 |
#include "llvm/IR/IntrinsicInst.h" |
| 95 |
#include "llvm/IR/Intrinsics.h" |
95 |
#include "llvm/IR/Intrinsics.h" |
| 96 |
#include "llvm/IR/IntrinsicsAArch64.h" |
96 |
#include "llvm/IR/IntrinsicsAArch64.h" |
| 97 |
#include "llvm/IR/IntrinsicsAMDGPU.h" |
97 |
#include "llvm/IR/IntrinsicsAMDGPU.h" |
| 98 |
#include "llvm/IR/IntrinsicsARM.h" |
98 |
#include "llvm/IR/IntrinsicsARM.h" |
| 99 |
#include "llvm/IR/IntrinsicsWebAssembly.h" |
99 |
#include "llvm/IR/IntrinsicsWebAssembly.h" |
| 100 |
#include "llvm/IR/LLVMContext.h" |
100 |
#include "llvm/IR/LLVMContext.h" |
| 101 |
#include "llvm/IR/Metadata.h" |
101 |
#include "llvm/IR/Metadata.h" |
| 102 |
#include "llvm/IR/Module.h" |
102 |
#include "llvm/IR/Module.h" |
| 103 |
#include "llvm/IR/ModuleSlotTracker.h" |
103 |
#include "llvm/IR/ModuleSlotTracker.h" |
| 104 |
#include "llvm/IR/PassManager.h" |
104 |
#include "llvm/IR/PassManager.h" |
| 105 |
#include "llvm/IR/Statepoint.h" |
105 |
#include "llvm/IR/Statepoint.h" |
| 106 |
#include "llvm/IR/Type.h" |
106 |
#include "llvm/IR/Type.h" |
| 107 |
#include "llvm/IR/Use.h" |
107 |
#include "llvm/IR/Use.h" |
| 108 |
#include "llvm/IR/User.h" |
108 |
#include "llvm/IR/User.h" |
| 109 |
#include "llvm/IR/Value.h" |
109 |
#include "llvm/IR/Value.h" |
| 110 |
#include "llvm/InitializePasses.h" |
110 |
#include "llvm/InitializePasses.h" |
| 111 |
#include "llvm/Pass.h" |
111 |
#include "llvm/Pass.h" |
| 112 |
#include "llvm/Support/AtomicOrdering.h" |
112 |
#include "llvm/Support/AtomicOrdering.h" |
| 113 |
#include "llvm/Support/Casting.h" |
113 |
#include "llvm/Support/Casting.h" |
| 114 |
#include "llvm/Support/CommandLine.h" |
114 |
#include "llvm/Support/CommandLine.h" |
| 115 |
#include "llvm/Support/ErrorHandling.h" |
115 |
#include "llvm/Support/ErrorHandling.h" |
| 116 |
#include "llvm/Support/MathExtras.h" |
116 |
#include "llvm/Support/MathExtras.h" |
| 117 |
#include "llvm/Support/raw_ostream.h" |
117 |
#include "llvm/Support/raw_ostream.h" |
| 118 |
#include |
118 |
#include |
| 119 |
#include |
119 |
#include |
| 120 |
#include |
120 |
#include |
| 121 |
#include |
121 |
#include |
| 122 |
#include |
122 |
#include |
| 123 |
#include |
123 |
#include |
| 124 |
#include |
124 |
#include |
| 125 |
|
125 |
|
| 126 |
using namespace llvm; |
126 |
using namespace llvm; |
| 127 |
|
127 |
|
| 128 |
static cl::opt VerifyNoAliasScopeDomination( |
128 |
static cl::opt VerifyNoAliasScopeDomination( |
| 129 |
"verify-noalias-scope-decl-dom", cl::Hidden, cl::init(false), |
129 |
"verify-noalias-scope-decl-dom", cl::Hidden, cl::init(false), |
| 130 |
cl::desc("Ensure that llvm.experimental.noalias.scope.decl for identical " |
130 |
cl::desc("Ensure that llvm.experimental.noalias.scope.decl for identical " |
| 131 |
"scopes are not dominating")); |
131 |
"scopes are not dominating")); |
| 132 |
|
132 |
|
| 133 |
namespace llvm { |
133 |
namespace llvm { |
| 134 |
|
134 |
|
| 135 |
struct VerifierSupport { |
135 |
struct VerifierSupport { |
| 136 |
raw_ostream *OS; |
136 |
raw_ostream *OS; |
| 137 |
const Module &M; |
137 |
const Module &M; |
| 138 |
ModuleSlotTracker MST; |
138 |
ModuleSlotTracker MST; |
| 139 |
Triple TT; |
139 |
Triple TT; |
| 140 |
const DataLayout &DL; |
140 |
const DataLayout &DL; |
| 141 |
LLVMContext &Context; |
141 |
LLVMContext &Context; |
| 142 |
|
142 |
|
| 143 |
/// Track the brokenness of the module while recursively visiting. |
143 |
/// Track the brokenness of the module while recursively visiting. |
| 144 |
bool Broken = false; |
144 |
bool Broken = false; |
| 145 |
/// Broken debug info can be "recovered" from by stripping the debug info. |
145 |
/// Broken debug info can be "recovered" from by stripping the debug info. |
| 146 |
bool BrokenDebugInfo = false; |
146 |
bool BrokenDebugInfo = false; |
| 147 |
/// Whether to treat broken debug info as an error. |
147 |
/// Whether to treat broken debug info as an error. |
| 148 |
bool TreatBrokenDebugInfoAsError = true; |
148 |
bool TreatBrokenDebugInfoAsError = true; |
| 149 |
|
149 |
|
| 150 |
explicit VerifierSupport(raw_ostream *OS, const Module &M) |
150 |
explicit VerifierSupport(raw_ostream *OS, const Module &M) |
| 151 |
: OS(OS), M(M), MST(&M), TT(M.getTargetTriple()), DL(M.getDataLayout()), |
151 |
: OS(OS), M(M), MST(&M), TT(M.getTargetTriple()), DL(M.getDataLayout()), |
| 152 |
Context(M.getContext()) {} |
152 |
Context(M.getContext()) {} |
| 153 |
|
153 |
|
| 154 |
private: |
154 |
private: |
| 155 |
void Write(const Module *M) { |
155 |
void Write(const Module *M) { |
| 156 |
*OS << "; ModuleID = '" << M->getModuleIdentifier() << "'\n"; |
156 |
*OS << "; ModuleID = '" << M->getModuleIdentifier() << "'\n"; |
| 157 |
} |
157 |
} |
| 158 |
|
158 |
|
| 159 |
void Write(const Value *V) { |
159 |
void Write(const Value *V) { |
| 160 |
if (V) |
160 |
if (V) |
| 161 |
Write(*V); |
161 |
Write(*V); |
| 162 |
} |
162 |
} |
| 163 |
|
163 |
|
| 164 |
void Write(const Value &V) { |
164 |
void Write(const Value &V) { |
| 165 |
if (isa(V)) { |
165 |
if (isa(V)) { |
| 166 |
V.print(*OS, MST); |
166 |
V.print(*OS, MST); |
| 167 |
*OS << '\n'; |
167 |
*OS << '\n'; |
| 168 |
} else { |
168 |
} else { |
| 169 |
V.printAsOperand(*OS, true, MST); |
169 |
V.printAsOperand(*OS, true, MST); |
| 170 |
*OS << '\n'; |
170 |
*OS << '\n'; |
| 171 |
} |
171 |
} |
| 172 |
} |
172 |
} |
| 173 |
|
173 |
|
| 174 |
void Write(const Metadata *MD) { |
174 |
void Write(const Metadata *MD) { |
| 175 |
if (!MD) |
175 |
if (!MD) |
| 176 |
return; |
176 |
return; |
| 177 |
MD->print(*OS, MST, &M); |
177 |
MD->print(*OS, MST, &M); |
| 178 |
*OS << '\n'; |
178 |
*OS << '\n'; |
| 179 |
} |
179 |
} |
| 180 |
|
180 |
|
| 181 |
template void Write(const MDTupleTypedArrayWrapper &MD) { |
181 |
template void Write(const MDTupleTypedArrayWrapper &MD) { |
| 182 |
Write(MD.get()); |
182 |
Write(MD.get()); |
| 183 |
} |
183 |
} |
| 184 |
|
184 |
|
| 185 |
void Write(const NamedMDNode *NMD) { |
185 |
void Write(const NamedMDNode *NMD) { |
| 186 |
if (!NMD) |
186 |
if (!NMD) |
| 187 |
return; |
187 |
return; |
| 188 |
NMD->print(*OS, MST); |
188 |
NMD->print(*OS, MST); |
| 189 |
*OS << '\n'; |
189 |
*OS << '\n'; |
| 190 |
} |
190 |
} |
| 191 |
|
191 |
|
| 192 |
void Write(Type *T) { |
192 |
void Write(Type *T) { |
| 193 |
if (!T) |
193 |
if (!T) |
| 194 |
return; |
194 |
return; |
| 195 |
*OS << ' ' << *T; |
195 |
*OS << ' ' << *T; |
| 196 |
} |
196 |
} |
| 197 |
|
197 |
|
| 198 |
void Write(const Comdat *C) { |
198 |
void Write(const Comdat *C) { |
| 199 |
if (!C) |
199 |
if (!C) |
| 200 |
return; |
200 |
return; |
| 201 |
*OS << *C; |
201 |
*OS << *C; |
| 202 |
} |
202 |
} |
| 203 |
|
203 |
|
| 204 |
void Write(const APInt *AI) { |
204 |
void Write(const APInt *AI) { |
| 205 |
if (!AI) |
205 |
if (!AI) |
| 206 |
return; |
206 |
return; |
| 207 |
*OS << *AI << '\n'; |
207 |
*OS << *AI << '\n'; |
| 208 |
} |
208 |
} |
| 209 |
|
209 |
|
| 210 |
void Write(const unsigned i) { *OS << i << '\n'; } |
210 |
void Write(const unsigned i) { *OS << i << '\n'; } |
| 211 |
|
211 |
|
| 212 |
// NOLINTNEXTLINE(readability-identifier-naming) |
212 |
// NOLINTNEXTLINE(readability-identifier-naming) |
| 213 |
void Write(const Attribute *A) { |
213 |
void Write(const Attribute *A) { |
| 214 |
if (!A) |
214 |
if (!A) |
| 215 |
return; |
215 |
return; |
| 216 |
*OS << A->getAsString() << '\n'; |
216 |
*OS << A->getAsString() << '\n'; |
| 217 |
} |
217 |
} |
| 218 |
|
218 |
|
| 219 |
// NOLINTNEXTLINE(readability-identifier-naming) |
219 |
// NOLINTNEXTLINE(readability-identifier-naming) |
| 220 |
void Write(const AttributeSet *AS) { |
220 |
void Write(const AttributeSet *AS) { |
| 221 |
if (!AS) |
221 |
if (!AS) |
| 222 |
return; |
222 |
return; |
| 223 |
*OS << AS->getAsString() << '\n'; |
223 |
*OS << AS->getAsString() << '\n'; |
| 224 |
} |
224 |
} |
| 225 |
|
225 |
|
| 226 |
// NOLINTNEXTLINE(readability-identifier-naming) |
226 |
// NOLINTNEXTLINE(readability-identifier-naming) |
| 227 |
void Write(const AttributeList *AL) { |
227 |
void Write(const AttributeList *AL) { |
| 228 |
if (!AL) |
228 |
if (!AL) |
| 229 |
return; |
229 |
return; |
| 230 |
AL->print(*OS); |
230 |
AL->print(*OS); |
| 231 |
} |
231 |
} |
| 232 |
|
232 |
|
| 233 |
void Write(Printable P) { *OS << P << '\n'; } |
233 |
void Write(Printable P) { *OS << P << '\n'; } |
| 234 |
|
234 |
|
| 235 |
template void Write(ArrayRef Vs) { |
235 |
template void Write(ArrayRef Vs) { |
| 236 |
for (const T &V : Vs) |
236 |
for (const T &V : Vs) |
| 237 |
Write(V); |
237 |
Write(V); |
| 238 |
} |
238 |
} |
| 239 |
|
239 |
|
| 240 |
template |
240 |
template |
| 241 |
void WriteTs(const T1 &V1, const Ts &... Vs) { |
241 |
void WriteTs(const T1 &V1, const Ts &... Vs) { |
| 242 |
Write(V1); |
242 |
Write(V1); |
| 243 |
WriteTs(Vs...); |
243 |
WriteTs(Vs...); |
| 244 |
} |
244 |
} |
| 245 |
|
245 |
|
| 246 |
template void WriteTs() {} |
246 |
template void WriteTs() {} |
| 247 |
|
247 |
|
| 248 |
public: |
248 |
public: |
| 249 |
/// A check failed, so printout out the condition and the message. |
249 |
/// A check failed, so printout out the condition and the message. |
| 250 |
/// |
250 |
/// |
| 251 |
/// This provides a nice place to put a breakpoint if you want to see why |
251 |
/// This provides a nice place to put a breakpoint if you want to see why |
| 252 |
/// something is not correct. |
252 |
/// something is not correct. |
| 253 |
void CheckFailed(const Twine &Message) { |
253 |
void CheckFailed(const Twine &Message) { |
| 254 |
if (OS) |
254 |
if (OS) |
| 255 |
*OS << Message << '\n'; |
255 |
*OS << Message << '\n'; |
| 256 |
Broken = true; |
256 |
Broken = true; |
| 257 |
} |
257 |
} |
| 258 |
|
258 |
|
| 259 |
/// A check failed (with values to print). |
259 |
/// A check failed (with values to print). |
| 260 |
/// |
260 |
/// |
| 261 |
/// This calls the Message-only version so that the above is easier to set a |
261 |
/// This calls the Message-only version so that the above is easier to set a |
| 262 |
/// breakpoint on. |
262 |
/// breakpoint on. |
| 263 |
template |
263 |
template |
| 264 |
void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) { |
264 |
void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) { |
| 265 |
CheckFailed(Message); |
265 |
CheckFailed(Message); |
| 266 |
if (OS) |
266 |
if (OS) |
| 267 |
WriteTs(V1, Vs...); |
267 |
WriteTs(V1, Vs...); |
| 268 |
} |
268 |
} |
| 269 |
|
269 |
|
| 270 |
/// A debug info check failed. |
270 |
/// A debug info check failed. |
| 271 |
void DebugInfoCheckFailed(const Twine &Message) { |
271 |
void DebugInfoCheckFailed(const Twine &Message) { |
| 272 |
if (OS) |
272 |
if (OS) |
| 273 |
*OS << Message << '\n'; |
273 |
*OS << Message << '\n'; |
| 274 |
Broken |= TreatBrokenDebugInfoAsError; |
274 |
Broken |= TreatBrokenDebugInfoAsError; |
| 275 |
BrokenDebugInfo = true; |
275 |
BrokenDebugInfo = true; |
| 276 |
} |
276 |
} |
| 277 |
|
277 |
|
| 278 |
/// A debug info check failed (with values to print). |
278 |
/// A debug info check failed (with values to print). |
| 279 |
template |
279 |
template |
| 280 |
void DebugInfoCheckFailed(const Twine &Message, const T1 &V1, |
280 |
void DebugInfoCheckFailed(const Twine &Message, const T1 &V1, |
| 281 |
const Ts &... Vs) { |
281 |
const Ts &... Vs) { |
| 282 |
DebugInfoCheckFailed(Message); |
282 |
DebugInfoCheckFailed(Message); |
| 283 |
if (OS) |
283 |
if (OS) |
| 284 |
WriteTs(V1, Vs...); |
284 |
WriteTs(V1, Vs...); |
| 285 |
} |
285 |
} |
| 286 |
}; |
286 |
}; |
| 287 |
|
287 |
|
| 288 |
} // namespace llvm |
288 |
} // namespace llvm |
| 289 |
|
289 |
|
| 290 |
namespace { |
290 |
namespace { |
| 291 |
|
291 |
|
| 292 |
class Verifier : public InstVisitor, VerifierSupport { |
292 |
class Verifier : public InstVisitor, VerifierSupport { |
| 293 |
friend class InstVisitor; |
293 |
friend class InstVisitor; |
| 294 |
|
294 |
|
| 295 |
// ISD::ArgFlagsTy::MemAlign only have 4 bits for alignment, so |
295 |
// ISD::ArgFlagsTy::MemAlign only have 4 bits for alignment, so |
| 296 |
// the alignment size should not exceed 2^15. Since encode(Align) |
296 |
// the alignment size should not exceed 2^15. Since encode(Align) |
| 297 |
// would plus the shift value by 1, the alignment size should |
297 |
// would plus the shift value by 1, the alignment size should |
| 298 |
// not exceed 2^14, otherwise it can NOT be properly lowered |
298 |
// not exceed 2^14, otherwise it can NOT be properly lowered |
| 299 |
// in backend. |
299 |
// in backend. |
| 300 |
static constexpr unsigned ParamMaxAlignment = 1 << 14; |
300 |
static constexpr unsigned ParamMaxAlignment = 1 << 14; |
| 301 |
DominatorTree DT; |
301 |
DominatorTree DT; |
| 302 |
|
302 |
|
| 303 |
/// When verifying a basic block, keep track of all of the |
303 |
/// When verifying a basic block, keep track of all of the |
| 304 |
/// instructions we have seen so far. |
304 |
/// instructions we have seen so far. |
| 305 |
/// |
305 |
/// |
| 306 |
/// This allows us to do efficient dominance checks for the case when an |
306 |
/// This allows us to do efficient dominance checks for the case when an |
| 307 |
/// instruction has an operand that is an instruction in the same block. |
307 |
/// instruction has an operand that is an instruction in the same block. |
| 308 |
SmallPtrSet InstsInThisBlock; |
308 |
SmallPtrSet InstsInThisBlock; |
| 309 |
|
309 |
|
| 310 |
/// Keep track of the metadata nodes that have been checked already. |
310 |
/// Keep track of the metadata nodes that have been checked already. |
| 311 |
SmallPtrSet MDNodes; |
311 |
SmallPtrSet MDNodes; |
| 312 |
|
312 |
|
| 313 |
/// Keep track which DISubprogram is attached to which function. |
313 |
/// Keep track which DISubprogram is attached to which function. |
| 314 |
DenseMap DISubprogramAttachments; |
314 |
DenseMap DISubprogramAttachments; |
| 315 |
|
315 |
|
| 316 |
/// Track all DICompileUnits visited. |
316 |
/// Track all DICompileUnits visited. |
| 317 |
SmallPtrSet CUVisited; |
317 |
SmallPtrSet CUVisited; |
| 318 |
|
318 |
|
| 319 |
/// The result type for a landingpad. |
319 |
/// The result type for a landingpad. |
| 320 |
Type *LandingPadResultTy; |
320 |
Type *LandingPadResultTy; |
| 321 |
|
321 |
|
| 322 |
/// Whether we've seen a call to @llvm.localescape in this function |
322 |
/// Whether we've seen a call to @llvm.localescape in this function |
| 323 |
/// already. |
323 |
/// already. |
| 324 |
bool SawFrameEscape; |
324 |
bool SawFrameEscape; |
| 325 |
|
325 |
|
| 326 |
/// Whether the current function has a DISubprogram attached to it. |
326 |
/// Whether the current function has a DISubprogram attached to it. |
| 327 |
bool HasDebugInfo = false; |
327 |
bool HasDebugInfo = false; |
| 328 |
|
328 |
|
| 329 |
/// The current source language. |
329 |
/// The current source language. |
| 330 |
dwarf::SourceLanguage CurrentSourceLang = dwarf::DW_LANG_lo_user; |
330 |
dwarf::SourceLanguage CurrentSourceLang = dwarf::DW_LANG_lo_user; |
| 331 |
|
331 |
|
| 332 |
/// Whether the current function has convergencectrl operand bundles. |
332 |
/// Whether the current function has convergencectrl operand bundles. |
| 333 |
enum { |
333 |
enum { |
| 334 |
ControlledConvergence, |
334 |
ControlledConvergence, |
| 335 |
UncontrolledConvergence, |
335 |
UncontrolledConvergence, |
| 336 |
NoConvergence |
336 |
NoConvergence |
| 337 |
} ConvergenceKind = NoConvergence; |
337 |
} ConvergenceKind = NoConvergence; |
| 338 |
|
338 |
|
| 339 |
/// Whether source was present on the first DIFile encountered in each CU. |
339 |
/// Whether source was present on the first DIFile encountered in each CU. |
| 340 |
DenseMap HasSourceDebugInfo; |
340 |
DenseMap HasSourceDebugInfo; |
| 341 |
|
341 |
|
| 342 |
/// Stores the count of how many objects were passed to llvm.localescape for a |
342 |
/// Stores the count of how many objects were passed to llvm.localescape for a |
| 343 |
/// given function and the largest index passed to llvm.localrecover. |
343 |
/// given function and the largest index passed to llvm.localrecover. |
| 344 |
DenseMap> FrameEscapeInfo; |
344 |
DenseMap> FrameEscapeInfo; |
| 345 |
|
345 |
|
| 346 |
// Maps catchswitches and cleanuppads that unwind to siblings to the |
346 |
// Maps catchswitches and cleanuppads that unwind to siblings to the |
| 347 |
// terminators that indicate the unwind, used to detect cycles therein. |
347 |
// terminators that indicate the unwind, used to detect cycles therein. |
| 348 |
MapVector SiblingFuncletInfo; |
348 |
MapVector SiblingFuncletInfo; |
| 349 |
|
349 |
|
| 350 |
/// Cache which blocks are in which funclet, if an EH funclet personality is |
350 |
/// Cache which blocks are in which funclet, if an EH funclet personality is |
| 351 |
/// in use. Otherwise empty. |
351 |
/// in use. Otherwise empty. |
| 352 |
DenseMap BlockEHFuncletColors; |
352 |
DenseMap BlockEHFuncletColors; |
| 353 |
|
353 |
|
| 354 |
/// Cache of constants visited in search of ConstantExprs. |
354 |
/// Cache of constants visited in search of ConstantExprs. |
| 355 |
SmallPtrSet ConstantExprVisited; |
355 |
SmallPtrSet ConstantExprVisited; |
| 356 |
|
356 |
|
| 357 |
/// Cache of declarations of the llvm.experimental.deoptimize. intrinsic. |
357 |
/// Cache of declarations of the llvm.experimental.deoptimize. intrinsic. |
| 358 |
SmallVector DeoptimizeDeclarations; |
358 |
SmallVector DeoptimizeDeclarations; |
| 359 |
|
359 |
|
| 360 |
/// Cache of attribute lists verified. |
360 |
/// Cache of attribute lists verified. |
| 361 |
SmallPtrSet AttributeListsVisited; |
361 |
SmallPtrSet AttributeListsVisited; |
| 362 |
|
362 |
|
| 363 |
// Verify that this GlobalValue is only used in this module. |
363 |
// Verify that this GlobalValue is only used in this module. |
| 364 |
// This map is used to avoid visiting uses twice. We can arrive at a user |
364 |
// This map is used to avoid visiting uses twice. We can arrive at a user |
| 365 |
// twice, if they have multiple operands. In particular for very large |
365 |
// twice, if they have multiple operands. In particular for very large |
| 366 |
// constant expressions, we can arrive at a particular user many times. |
366 |
// constant expressions, we can arrive at a particular user many times. |
| 367 |
SmallPtrSet GlobalValueVisited; |
367 |
SmallPtrSet GlobalValueVisited; |
| 368 |
|
368 |
|
| 369 |
// Keeps track of duplicate function argument debug info. |
369 |
// Keeps track of duplicate function argument debug info. |
| 370 |
SmallVector DebugFnArgs; |
370 |
SmallVector DebugFnArgs; |
| 371 |
|
371 |
|
| 372 |
TBAAVerifier TBAAVerifyHelper; |
372 |
TBAAVerifier TBAAVerifyHelper; |
| 373 |
|
373 |
|
| 374 |
SmallVector NoAliasScopeDecls; |
374 |
SmallVector NoAliasScopeDecls; |
| 375 |
|
375 |
|
| 376 |
void checkAtomicMemAccessSize(Type *Ty, const Instruction *I); |
376 |
void checkAtomicMemAccessSize(Type *Ty, const Instruction *I); |
| 377 |
|
377 |
|
| 378 |
public: |
378 |
public: |
| 379 |
explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError, |
379 |
explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError, |
| 380 |
const Module &M) |
380 |
const Module &M) |
| 381 |
: VerifierSupport(OS, M), LandingPadResultTy(nullptr), |
381 |
: VerifierSupport(OS, M), LandingPadResultTy(nullptr), |
| 382 |
SawFrameEscape(false), TBAAVerifyHelper(this) { |
382 |
SawFrameEscape(false), TBAAVerifyHelper(this) { |
| 383 |
TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError; |
383 |
TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError; |
| 384 |
} |
384 |
} |
| 385 |
|
385 |
|
| 386 |
bool hasBrokenDebugInfo() const { return BrokenDebugInfo; } |
386 |
bool hasBrokenDebugInfo() const { return BrokenDebugInfo; } |
| 387 |
|
387 |
|
| 388 |
bool verify(const Function &F) { |
388 |
bool verify(const Function &F) { |
| 389 |
assert(F.getParent() == &M && |
389 |
assert(F.getParent() == &M && |
| 390 |
"An instance of this class only works with a specific module!"); |
390 |
"An instance of this class only works with a specific module!"); |
| 391 |
|
391 |
|
| 392 |
// First ensure the function is well-enough formed to compute dominance |
392 |
// First ensure the function is well-enough formed to compute dominance |
| 393 |
// information, and directly compute a dominance tree. We don't rely on the |
393 |
// information, and directly compute a dominance tree. We don't rely on the |
| 394 |
// pass manager to provide this as it isolates us from a potentially |
394 |
// pass manager to provide this as it isolates us from a potentially |
| 395 |
// out-of-date dominator tree and makes it significantly more complex to run |
395 |
// out-of-date dominator tree and makes it significantly more complex to run |
| 396 |
// this code outside of a pass manager. |
396 |
// this code outside of a pass manager. |
| 397 |
// FIXME: It's really gross that we have to cast away constness here. |
397 |
// FIXME: It's really gross that we have to cast away constness here. |
| 398 |
if (!F.empty()) |
398 |
if (!F.empty()) |
| 399 |
DT.recalculate(const_cast(F)); |
399 |
DT.recalculate(const_cast(F)); |
| 400 |
|
400 |
|
| 401 |
for (const BasicBlock &BB : F) { |
401 |
for (const BasicBlock &BB : F) { |
| 402 |
if (!BB.empty() && BB.back().isTerminator()) |
402 |
if (!BB.empty() && BB.back().isTerminator()) |
| 403 |
continue; |
403 |
continue; |
| 404 |
|
404 |
|
| 405 |
if (OS) { |
405 |
if (OS) { |
| 406 |
*OS << "Basic Block in function '" << F.getName() |
406 |
*OS << "Basic Block in function '" << F.getName() |
| 407 |
<< "' does not have terminator!\n"; |
407 |
<< "' does not have terminator!\n"; |
| 408 |
BB.printAsOperand(*OS, true, MST); |
408 |
BB.printAsOperand(*OS, true, MST); |
| 409 |
*OS << "\n"; |
409 |
*OS << "\n"; |
| 410 |
} |
410 |
} |
| 411 |
return false; |
411 |
return false; |
| 412 |
} |
412 |
} |
| 413 |
|
413 |
|
| 414 |
Broken = false; |
414 |
Broken = false; |
| 415 |
// FIXME: We strip const here because the inst visitor strips const. |
415 |
// FIXME: We strip const here because the inst visitor strips const. |
| 416 |
visit(const_cast(F)); |
416 |
visit(const_cast(F)); |
| 417 |
verifySiblingFuncletUnwinds(); |
417 |
verifySiblingFuncletUnwinds(); |
| 418 |
if (ConvergenceKind == ControlledConvergence) |
418 |
if (ConvergenceKind == ControlledConvergence) |
| 419 |
verifyConvergenceControl(const_cast(F)); |
419 |
verifyConvergenceControl(const_cast(F)); |
| 420 |
InstsInThisBlock.clear(); |
420 |
InstsInThisBlock.clear(); |
| 421 |
DebugFnArgs.clear(); |
421 |
DebugFnArgs.clear(); |
| 422 |
LandingPadResultTy = nullptr; |
422 |
LandingPadResultTy = nullptr; |
| 423 |
SawFrameEscape = false; |
423 |
SawFrameEscape = false; |
| 424 |
SiblingFuncletInfo.clear(); |
424 |
SiblingFuncletInfo.clear(); |
| 425 |
verifyNoAliasScopeDecl(); |
425 |
verifyNoAliasScopeDecl(); |
| 426 |
NoAliasScopeDecls.clear(); |
426 |
NoAliasScopeDecls.clear(); |
| 427 |
ConvergenceKind = NoConvergence; |
427 |
ConvergenceKind = NoConvergence; |
| 428 |
|
428 |
|
| 429 |
return !Broken; |
429 |
return !Broken; |
| 430 |
} |
430 |
} |
| 431 |
|
431 |
|
| 432 |
/// Verify the module that this instance of \c Verifier was initialized with. |
432 |
/// Verify the module that this instance of \c Verifier was initialized with. |
| 433 |
bool verify() { |
433 |
bool verify() { |
| 434 |
Broken = false; |
434 |
Broken = false; |
| 435 |
|
435 |
|
| 436 |
// Collect all declarations of the llvm.experimental.deoptimize intrinsic. |
436 |
// Collect all declarations of the llvm.experimental.deoptimize intrinsic. |
| 437 |
for (const Function &F : M) |
437 |
for (const Function &F : M) |
| 438 |
if (F.getIntrinsicID() == Intrinsic::experimental_deoptimize) |
438 |
if (F.getIntrinsicID() == Intrinsic::experimental_deoptimize) |
| 439 |
DeoptimizeDeclarations.push_back(&F); |
439 |
DeoptimizeDeclarations.push_back(&F); |
| 440 |
|
440 |
|
| 441 |
// Now that we've visited every function, verify that we never asked to |
441 |
// Now that we've visited every function, verify that we never asked to |
| 442 |
// recover a frame index that wasn't escaped. |
442 |
// recover a frame index that wasn't escaped. |
| 443 |
verifyFrameRecoverIndices(); |
443 |
verifyFrameRecoverIndices(); |
| 444 |
for (const GlobalVariable &GV : M.globals()) |
444 |
for (const GlobalVariable &GV : M.globals()) |
| 445 |
visitGlobalVariable(GV); |
445 |
visitGlobalVariable(GV); |
| 446 |
|
446 |
|
| 447 |
for (const GlobalAlias &GA : M.aliases()) |
447 |
for (const GlobalAlias &GA : M.aliases()) |
| 448 |
visitGlobalAlias(GA); |
448 |
visitGlobalAlias(GA); |
| 449 |
|
449 |
|
| 450 |
for (const GlobalIFunc &GI : M.ifuncs()) |
450 |
for (const GlobalIFunc &GI : M.ifuncs()) |
| 451 |
visitGlobalIFunc(GI); |
451 |
visitGlobalIFunc(GI); |
| 452 |
|
452 |
|
| 453 |
for (const NamedMDNode &NMD : M.named_metadata()) |
453 |
for (const NamedMDNode &NMD : M.named_metadata()) |
| 454 |
visitNamedMDNode(NMD); |
454 |
visitNamedMDNode(NMD); |
| 455 |
|
455 |
|
| 456 |
for (const StringMapEntry &SMEC : M.getComdatSymbolTable()) |
456 |
for (const StringMapEntry &SMEC : M.getComdatSymbolTable()) |
| 457 |
visitComdat(SMEC.getValue()); |
457 |
visitComdat(SMEC.getValue()); |
| 458 |
|
458 |
|
| 459 |
visitModuleFlags(); |
459 |
visitModuleFlags(); |
| 460 |
visitModuleIdents(); |
460 |
visitModuleIdents(); |
| 461 |
visitModuleCommandLines(); |
461 |
visitModuleCommandLines(); |
| 462 |
|
462 |
|
| 463 |
verifyCompileUnits(); |
463 |
verifyCompileUnits(); |
| 464 |
|
464 |
|
| 465 |
verifyDeoptimizeCallingConvs(); |
465 |
verifyDeoptimizeCallingConvs(); |
| 466 |
DISubprogramAttachments.clear(); |
466 |
DISubprogramAttachments.clear(); |
| 467 |
return !Broken; |
467 |
return !Broken; |
| 468 |
} |
468 |
} |
| 469 |
|
469 |
|
| 470 |
private: |
470 |
private: |
| 471 |
/// Whether a metadata node is allowed to be, or contain, a DILocation. |
471 |
/// Whether a metadata node is allowed to be, or contain, a DILocation. |
| 472 |
enum class AreDebugLocsAllowed { No, Yes }; |
472 |
enum class AreDebugLocsAllowed { No, Yes }; |
| 473 |
|
473 |
|
| 474 |
// Verification methods... |
474 |
// Verification methods... |
| 475 |
void visitGlobalValue(const GlobalValue &GV); |
475 |
void visitGlobalValue(const GlobalValue &GV); |
| 476 |
void visitGlobalVariable(const GlobalVariable &GV); |
476 |
void visitGlobalVariable(const GlobalVariable &GV); |
| 477 |
void visitGlobalAlias(const GlobalAlias &GA); |
477 |
void visitGlobalAlias(const GlobalAlias &GA); |
| 478 |
void visitGlobalIFunc(const GlobalIFunc &GI); |
478 |
void visitGlobalIFunc(const GlobalIFunc &GI); |
| 479 |
void visitAliaseeSubExpr(const GlobalAlias &A, const Constant &C); |
479 |
void visitAliaseeSubExpr(const GlobalAlias &A, const Constant &C); |
| 480 |
void visitAliaseeSubExpr(SmallPtrSetImpl &Visited, |
480 |
void visitAliaseeSubExpr(SmallPtrSetImpl &Visited, |
| 481 |
const GlobalAlias &A, const Constant &C); |
481 |
const GlobalAlias &A, const Constant &C); |
| 482 |
void visitNamedMDNode(const NamedMDNode &NMD); |
482 |
void visitNamedMDNode(const NamedMDNode &NMD); |
| 483 |
void visitMDNode(const MDNode &MD, AreDebugLocsAllowed AllowLocs); |
483 |
void visitMDNode(const MDNode &MD, AreDebugLocsAllowed AllowLocs); |
| 484 |
void visitMetadataAsValue(const MetadataAsValue &MD, Function *F); |
484 |
void visitMetadataAsValue(const MetadataAsValue &MD, Function *F); |
| 485 |
void visitValueAsMetadata(const ValueAsMetadata &MD, Function *F); |
485 |
void visitValueAsMetadata(const ValueAsMetadata &MD, Function *F); |
| 486 |
void visitComdat(const Comdat &C); |
486 |
void visitComdat(const Comdat &C); |
| 487 |
void visitModuleIdents(); |
487 |
void visitModuleIdents(); |
| 488 |
void visitModuleCommandLines(); |
488 |
void visitModuleCommandLines(); |
| 489 |
void visitModuleFlags(); |
489 |
void visitModuleFlags(); |
| 490 |
void visitModuleFlag(const MDNode *Op, |
490 |
void visitModuleFlag(const MDNode *Op, |
| 491 |
DenseMap &SeenIDs, |
491 |
DenseMap &SeenIDs, |
| 492 |
SmallVectorImpl &Requirements); |
492 |
SmallVectorImpl &Requirements); |
| 493 |
void visitModuleFlagCGProfileEntry(const MDOperand &MDO); |
493 |
void visitModuleFlagCGProfileEntry(const MDOperand &MDO); |
| 494 |
void visitFunction(const Function &F); |
494 |
void visitFunction(const Function &F); |
| 495 |
void visitBasicBlock(BasicBlock &BB); |
495 |
void visitBasicBlock(BasicBlock &BB); |
| 496 |
void verifyRangeMetadata(const Value &V, const MDNode *Range, Type *Ty, |
496 |
void verifyRangeMetadata(const Value &V, const MDNode *Range, Type *Ty, |
| 497 |
bool IsAbsoluteSymbol); |
497 |
bool IsAbsoluteSymbol); |
| 498 |
void visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty); |
498 |
void visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty); |
| 499 |
void visitDereferenceableMetadata(Instruction &I, MDNode *MD); |
499 |
void visitDereferenceableMetadata(Instruction &I, MDNode *MD); |
| 500 |
void visitProfMetadata(Instruction &I, MDNode *MD); |
500 |
void visitProfMetadata(Instruction &I, MDNode *MD); |
| 501 |
void visitCallStackMetadata(MDNode *MD); |
501 |
void visitCallStackMetadata(MDNode *MD); |
| 502 |
void visitMemProfMetadata(Instruction &I, MDNode *MD); |
502 |
void visitMemProfMetadata(Instruction &I, MDNode *MD); |
| 503 |
void visitCallsiteMetadata(Instruction &I, MDNode *MD); |
503 |
void visitCallsiteMetadata(Instruction &I, MDNode *MD); |
| 504 |
void visitDIAssignIDMetadata(Instruction &I, MDNode *MD); |
504 |
void visitDIAssignIDMetadata(Instruction &I, MDNode *MD); |
| 505 |
void visitAnnotationMetadata(MDNode *Annotation); |
505 |
void visitAnnotationMetadata(MDNode *Annotation); |
| 506 |
void visitAliasScopeMetadata(const MDNode *MD); |
506 |
void visitAliasScopeMetadata(const MDNode *MD); |
| 507 |
void visitAliasScopeListMetadata(const MDNode *MD); |
507 |
void visitAliasScopeListMetadata(const MDNode *MD); |
| 508 |
void visitAccessGroupMetadata(const MDNode *MD); |
508 |
void visitAccessGroupMetadata(const MDNode *MD); |
| 509 |
|
509 |
|
| 510 |
template bool isValidMetadataArray(const MDTuple &N); |
510 |
template bool isValidMetadataArray(const MDTuple &N); |
| 511 |
#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N); |
511 |
#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N); |
| 512 |
#include "llvm/IR/Metadata.def" |
512 |
#include "llvm/IR/Metadata.def" |
| 513 |
void visitDIScope(const DIScope &N); |
513 |
void visitDIScope(const DIScope &N); |
| 514 |
void visitDIVariable(const DIVariable &N); |
514 |
void visitDIVariable(const DIVariable &N); |
| 515 |
void visitDILexicalBlockBase(const DILexicalBlockBase &N); |
515 |
void visitDILexicalBlockBase(const DILexicalBlockBase &N); |
| 516 |
void visitDITemplateParameter(const DITemplateParameter &N); |
516 |
void visitDITemplateParameter(const DITemplateParameter &N); |
| 517 |
|
517 |
|
| 518 |
void visitTemplateParams(const MDNode &N, const Metadata &RawParams); |
518 |
void visitTemplateParams(const MDNode &N, const Metadata &RawParams); |
| 519 |
|
519 |
|
| 520 |
// InstVisitor overrides... |
520 |
// InstVisitor overrides... |
| 521 |
using InstVisitor::visit; |
521 |
using InstVisitor::visit; |
| 522 |
void visit(Instruction &I); |
522 |
void visit(Instruction &I); |
| 523 |
|
523 |
|
| 524 |
void visitTruncInst(TruncInst &I); |
524 |
void visitTruncInst(TruncInst &I); |
| 525 |
void visitZExtInst(ZExtInst &I); |
525 |
void visitZExtInst(ZExtInst &I); |
| 526 |
void visitSExtInst(SExtInst &I); |
526 |
void visitSExtInst(SExtInst &I); |
| 527 |
void visitFPTruncInst(FPTruncInst &I); |
527 |
void visitFPTruncInst(FPTruncInst &I); |
| 528 |
void visitFPExtInst(FPExtInst &I); |
528 |
void visitFPExtInst(FPExtInst &I); |
| 529 |
void visitFPToUIInst(FPToUIInst &I); |
529 |
void visitFPToUIInst(FPToUIInst &I); |
| 530 |
void visitFPToSIInst(FPToSIInst &I); |
530 |
void visitFPToSIInst(FPToSIInst &I); |
| 531 |
void visitUIToFPInst(UIToFPInst &I); |
531 |
void visitUIToFPInst(UIToFPInst &I); |
| 532 |
void visitSIToFPInst(SIToFPInst &I); |
532 |
void visitSIToFPInst(SIToFPInst &I); |
| 533 |
void visitIntToPtrInst(IntToPtrInst &I); |
533 |
void visitIntToPtrInst(IntToPtrInst &I); |
| 534 |
void visitPtrToIntInst(PtrToIntInst &I); |
534 |
void visitPtrToIntInst(PtrToIntInst &I); |
| 535 |
void visitBitCastInst(BitCastInst &I); |
535 |
void visitBitCastInst(BitCastInst &I); |
| 536 |
void visitAddrSpaceCastInst(AddrSpaceCastInst &I); |
536 |
void visitAddrSpaceCastInst(AddrSpaceCastInst &I); |
| 537 |
void visitPHINode(PHINode &PN); |
537 |
void visitPHINode(PHINode &PN); |
| 538 |
void visitCallBase(CallBase &Call); |
538 |
void visitCallBase(CallBase &Call); |
| 539 |
void visitUnaryOperator(UnaryOperator &U); |
539 |
void visitUnaryOperator(UnaryOperator &U); |
| 540 |
void visitBinaryOperator(BinaryOperator &B); |
540 |
void visitBinaryOperator(BinaryOperator &B); |
| 541 |
void visitICmpInst(ICmpInst &IC); |
541 |
void visitICmpInst(ICmpInst &IC); |
| 542 |
void visitFCmpInst(FCmpInst &FC); |
542 |
void visitFCmpInst(FCmpInst &FC); |
| 543 |
void visitExtractElementInst(ExtractElementInst &EI); |
543 |
void visitExtractElementInst(ExtractElementInst &EI); |
| 544 |
void visitInsertElementInst(InsertElementInst &EI); |
544 |
void visitInsertElementInst(InsertElementInst &EI); |
| 545 |
void visitShuffleVectorInst(ShuffleVectorInst &EI); |
545 |
void visitShuffleVectorInst(ShuffleVectorInst &EI); |
| 546 |
void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); } |
546 |
void visitVAArgInst(VAArgInst &VAA) { visitInstruction(VAA); } |
| 547 |
void visitCallInst(CallInst &CI); |
547 |
void visitCallInst(CallInst &CI); |
| 548 |
void visitInvokeInst(InvokeInst &II); |
548 |
void visitInvokeInst(InvokeInst &II); |
| 549 |
void visitGetElementPtrInst(GetElementPtrInst &GEP); |
549 |
void visitGetElementPtrInst(GetElementPtrInst &GEP); |
| 550 |
void visitLoadInst(LoadInst &LI); |
550 |
void visitLoadInst(LoadInst &LI); |
| 551 |
void visitStoreInst(StoreInst &SI); |
551 |
void visitStoreInst(StoreInst &SI); |
| 552 |
void verifyDominatesUse(Instruction &I, unsigned i); |
552 |
void verifyDominatesUse(Instruction &I, unsigned i); |
| 553 |
void visitInstruction(Instruction &I); |
553 |
void visitInstruction(Instruction &I); |
| 554 |
void visitTerminator(Instruction &I); |
554 |
void visitTerminator(Instruction &I); |
| 555 |
void visitBranchInst(BranchInst &BI); |
555 |
void visitBranchInst(BranchInst &BI); |
| 556 |
void visitReturnInst(ReturnInst &RI); |
556 |
void visitReturnInst(ReturnInst &RI); |
| 557 |
void visitSwitchInst(SwitchInst &SI); |
557 |
void visitSwitchInst(SwitchInst &SI); |
| 558 |
void visitIndirectBrInst(IndirectBrInst &BI); |
558 |
void visitIndirectBrInst(IndirectBrInst &BI); |
| 559 |
void visitCallBrInst(CallBrInst &CBI); |
559 |
void visitCallBrInst(CallBrInst &CBI); |
| 560 |
void visitSelectInst(SelectInst &SI); |
560 |
void visitSelectInst(SelectInst &SI); |
| 561 |
void visitUserOp1(Instruction &I); |
561 |
void visitUserOp1(Instruction &I); |
| 562 |
void visitUserOp2(Instruction &I) { visitUserOp1(I); } |
562 |
void visitUserOp2(Instruction &I) { visitUserOp1(I); } |
| 563 |
void visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call); |
563 |
void visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call); |
| 564 |
void visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI); |
564 |
void visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI); |
| 565 |
void visitVPIntrinsic(VPIntrinsic &VPI); |
565 |
void visitVPIntrinsic(VPIntrinsic &VPI); |
| 566 |
void visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII); |
566 |
void visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII); |
| 567 |
void visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI); |
567 |
void visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI); |
| 568 |
void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI); |
568 |
void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI); |
| 569 |
void visitAtomicRMWInst(AtomicRMWInst &RMWI); |
569 |
void visitAtomicRMWInst(AtomicRMWInst &RMWI); |
| 570 |
void visitFenceInst(FenceInst &FI); |
570 |
void visitFenceInst(FenceInst &FI); |
| 571 |
void visitAllocaInst(AllocaInst &AI); |
571 |
void visitAllocaInst(AllocaInst &AI); |
| 572 |
void visitExtractValueInst(ExtractValueInst &EVI); |
572 |
void visitExtractValueInst(ExtractValueInst &EVI); |
| 573 |
void visitInsertValueInst(InsertValueInst &IVI); |
573 |
void visitInsertValueInst(InsertValueInst &IVI); |
| 574 |
void visitEHPadPredecessors(Instruction &I); |
574 |
void visitEHPadPredecessors(Instruction &I); |
| 575 |
void visitLandingPadInst(LandingPadInst &LPI); |
575 |
void visitLandingPadInst(LandingPadInst &LPI); |
| 576 |
void visitResumeInst(ResumeInst &RI); |
576 |
void visitResumeInst(ResumeInst &RI); |
| 577 |
void visitCatchPadInst(CatchPadInst &CPI); |
577 |
void visitCatchPadInst(CatchPadInst &CPI); |
| 578 |
void visitCatchReturnInst(CatchReturnInst &CatchReturn); |
578 |
void visitCatchReturnInst(CatchReturnInst &CatchReturn); |
| 579 |
void visitCleanupPadInst(CleanupPadInst &CPI); |
579 |
void visitCleanupPadInst(CleanupPadInst &CPI); |
| 580 |
void visitFuncletPadInst(FuncletPadInst &FPI); |
580 |
void visitFuncletPadInst(FuncletPadInst &FPI); |
| 581 |
void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch); |
581 |
void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch); |
| 582 |
void visitCleanupReturnInst(CleanupReturnInst &CRI); |
582 |
void visitCleanupReturnInst(CleanupReturnInst &CRI); |
| 583 |
|
583 |
|
| 584 |
void verifySwiftErrorCall(CallBase &Call, const Value *SwiftErrorVal); |
584 |
void verifySwiftErrorCall(CallBase &Call, const Value *SwiftErrorVal); |
| 585 |
void verifySwiftErrorValue(const Value *SwiftErrorVal); |
585 |
void verifySwiftErrorValue(const Value *SwiftErrorVal); |
| 586 |
void verifyTailCCMustTailAttrs(const AttrBuilder &Attrs, StringRef Context); |
586 |
void verifyTailCCMustTailAttrs(const AttrBuilder &Attrs, StringRef Context); |
| 587 |
void verifyMustTailCall(CallInst &CI); |
587 |
void verifyMustTailCall(CallInst &CI); |
| 588 |
bool verifyAttributeCount(AttributeList Attrs, unsigned Params); |
588 |
bool verifyAttributeCount(AttributeList Attrs, unsigned Params); |
| 589 |
void verifyAttributeTypes(AttributeSet Attrs, const Value *V); |
589 |
void verifyAttributeTypes(AttributeSet Attrs, const Value *V); |
| 590 |
void verifyParameterAttrs(AttributeSet Attrs, Type *Ty, const Value *V); |
590 |
void verifyParameterAttrs(AttributeSet Attrs, Type *Ty, const Value *V); |
| 591 |
void checkUnsignedBaseTenFuncAttr(AttributeList Attrs, StringRef Attr, |
591 |
void checkUnsignedBaseTenFuncAttr(AttributeList Attrs, StringRef Attr, |
| 592 |
const Value *V); |
592 |
const Value *V); |
| 593 |
void verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, |
593 |
void verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, |
| 594 |
const Value *V, bool IsIntrinsic, bool IsInlineAsm); |
594 |
const Value *V, bool IsIntrinsic, bool IsInlineAsm); |
| 595 |
void verifyFunctionMetadata(ArrayRef> MDs); |
595 |
void verifyFunctionMetadata(ArrayRef> MDs); |
| 596 |
|
596 |
|
| 597 |
void visitConstantExprsRecursively(const Constant *EntryC); |
597 |
void visitConstantExprsRecursively(const Constant *EntryC); |
| 598 |
void visitConstantExpr(const ConstantExpr *CE); |
598 |
void visitConstantExpr(const ConstantExpr *CE); |
| 599 |
void verifyInlineAsmCall(const CallBase &Call); |
599 |
void verifyInlineAsmCall(const CallBase &Call); |
| 600 |
void verifyStatepoint(const CallBase &Call); |
600 |
void verifyStatepoint(const CallBase &Call); |
| 601 |
void verifyFrameRecoverIndices(); |
601 |
void verifyFrameRecoverIndices(); |
| 602 |
void verifySiblingFuncletUnwinds(); |
602 |
void verifySiblingFuncletUnwinds(); |
| 603 |
void verifyConvergenceControl(Function &F); |
603 |
void verifyConvergenceControl(Function &F); |
| 604 |
|
604 |
|
| 605 |
void verifyFragmentExpression(const DbgVariableIntrinsic &I); |
605 |
void verifyFragmentExpression(const DbgVariableIntrinsic &I); |
| 606 |
template |
606 |
template |
| 607 |
void verifyFragmentExpression(const DIVariable &V, |
607 |
void verifyFragmentExpression(const DIVariable &V, |
| 608 |
DIExpression::FragmentInfo Fragment, |
608 |
DIExpression::FragmentInfo Fragment, |
| 609 |
ValueOrMetadata *Desc); |
609 |
ValueOrMetadata *Desc); |
| 610 |
void verifyFnArgs(const DbgVariableIntrinsic &I); |
610 |
void verifyFnArgs(const DbgVariableIntrinsic &I); |
| 611 |
void verifyNotEntryValue(const DbgVariableIntrinsic &I); |
611 |
void verifyNotEntryValue(const DbgVariableIntrinsic &I); |
| 612 |
|
612 |
|
| 613 |
/// Module-level debug info verification... |
613 |
/// Module-level debug info verification... |
| 614 |
void verifyCompileUnits(); |
614 |
void verifyCompileUnits(); |
| 615 |
|
615 |
|
| 616 |
/// Module-level verification that all @llvm.experimental.deoptimize |
616 |
/// Module-level verification that all @llvm.experimental.deoptimize |
| 617 |
/// declarations share the same calling convention. |
617 |
/// declarations share the same calling convention. |
| 618 |
void verifyDeoptimizeCallingConvs(); |
618 |
void verifyDeoptimizeCallingConvs(); |
| 619 |
|
619 |
|
| 620 |
void verifyAttachedCallBundle(const CallBase &Call, |
620 |
void verifyAttachedCallBundle(const CallBase &Call, |
| 621 |
const OperandBundleUse &BU); |
621 |
const OperandBundleUse &BU); |
| 622 |
|
622 |
|
| 623 |
/// Verify all-or-nothing property of DIFile source attribute within a CU. |
623 |
/// Verify all-or-nothing property of DIFile source attribute within a CU. |
| 624 |
void verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F); |
624 |
void verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F); |
| 625 |
|
625 |
|
| 626 |
/// Verify the llvm.experimental.noalias.scope.decl declarations |
626 |
/// Verify the llvm.experimental.noalias.scope.decl declarations |
| 627 |
void verifyNoAliasScopeDecl(); |
627 |
void verifyNoAliasScopeDecl(); |
| 628 |
}; |
628 |
}; |
| 629 |
|
629 |
|
| 630 |
} // end anonymous namespace |
630 |
} // end anonymous namespace |
| 631 |
|
631 |
|
| 632 |
/// We know that cond should be true, if not print an error message. |
632 |
/// We know that cond should be true, if not print an error message. |
| 633 |
#define Check(C, ...) \ |
633 |
#define Check(C, ...) \ |
| 634 |
do { \ |
634 |
do { \ |
| 635 |
if (!(C)) { \ |
635 |
if (!(C)) { \ |
| 636 |
CheckFailed(__VA_ARGS__); \ |
636 |
CheckFailed(__VA_ARGS__); \ |
| 637 |
return; \ |
637 |
return; \ |
| 638 |
} \ |
638 |
} \ |
| 639 |
} while (false) |
639 |
} while (false) |
| 640 |
|
640 |
|
| 641 |
/// We know that a debug info condition should be true, if not print |
641 |
/// We know that a debug info condition should be true, if not print |
| 642 |
/// an error message. |
642 |
/// an error message. |
| 643 |
#define CheckDI(C, ...) \ |
643 |
#define CheckDI(C, ...) \ |
| 644 |
do { \ |
644 |
do { \ |
| 645 |
if (!(C)) { \ |
645 |
if (!(C)) { \ |
| 646 |
DebugInfoCheckFailed(__VA_ARGS__); \ |
646 |
DebugInfoCheckFailed(__VA_ARGS__); \ |
| 647 |
return; \ |
647 |
return; \ |
| 648 |
} \ |
648 |
} \ |
| 649 |
} while (false) |
649 |
} while (false) |
| 650 |
|
650 |
|
| 651 |
void Verifier::visit(Instruction &I) { |
651 |
void Verifier::visit(Instruction &I) { |
| 652 |
for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) |
652 |
for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) |
| 653 |
Check(I.getOperand(i) != nullptr, "Operand is null", &I); |
653 |
Check(I.getOperand(i) != nullptr, "Operand is null", &I); |
| 654 |
InstVisitor::visit(I); |
654 |
InstVisitor::visit(I); |
| 655 |
} |
655 |
} |
| 656 |
|
656 |
|
| 657 |
// Helper to iterate over indirect users. By returning false, the callback can ask to stop traversing further. |
657 |
// Helper to iterate over indirect users. By returning false, the callback can ask to stop traversing further. |
| 658 |
static void forEachUser(const Value *User, |
658 |
static void forEachUser(const Value *User, |
| 659 |
SmallPtrSet &Visited, |
659 |
SmallPtrSet &Visited, |
| 660 |
llvm::function_ref Callback) { |
660 |
llvm::function_ref Callback) { |
| 661 |
if (!Visited.insert(User).second) |
661 |
if (!Visited.insert(User).second) |
| 662 |
return; |
662 |
return; |
| 663 |
|
663 |
|
| 664 |
SmallVector WorkList; |
664 |
SmallVector WorkList; |
| 665 |
append_range(WorkList, User->materialized_users()); |
665 |
append_range(WorkList, User->materialized_users()); |
| 666 |
while (!WorkList.empty()) { |
666 |
while (!WorkList.empty()) { |
| 667 |
const Value *Cur = WorkList.pop_back_val(); |
667 |
const Value *Cur = WorkList.pop_back_val(); |
| 668 |
if (!Visited.insert(Cur).second) |
668 |
if (!Visited.insert(Cur).second) |
| 669 |
continue; |
669 |
continue; |
| 670 |
if (Callback(Cur)) |
670 |
if (Callback(Cur)) |
| 671 |
append_range(WorkList, Cur->materialized_users()); |
671 |
append_range(WorkList, Cur->materialized_users()); |
| 672 |
} |
672 |
} |
| 673 |
} |
673 |
} |
| 674 |
|
674 |
|
| 675 |
void Verifier::visitGlobalValue(const GlobalValue &GV) { |
675 |
void Verifier::visitGlobalValue(const GlobalValue &GV) { |
| 676 |
Check(!GV.isDeclaration() || GV.hasValidDeclarationLinkage(), |
676 |
Check(!GV.isDeclaration() || GV.hasValidDeclarationLinkage(), |
| 677 |
"Global is external, but doesn't have external or weak linkage!", &GV); |
677 |
"Global is external, but doesn't have external or weak linkage!", &GV); |
| 678 |
|
678 |
|
| 679 |
if (const GlobalObject *GO = dyn_cast(&GV)) { |
679 |
if (const GlobalObject *GO = dyn_cast(&GV)) { |
| 680 |
|
680 |
|
| 681 |
if (MaybeAlign A = GO->getAlign()) { |
681 |
if (MaybeAlign A = GO->getAlign()) { |
| 682 |
Check(A->value() <= Value::MaximumAlignment, |
682 |
Check(A->value() <= Value::MaximumAlignment, |
| 683 |
"huge alignment values are unsupported", GO); |
683 |
"huge alignment values are unsupported", GO); |
| 684 |
} |
684 |
} |
| 685 |
|
685 |
|
| 686 |
if (const MDNode *Associated = |
686 |
if (const MDNode *Associated = |
| 687 |
GO->getMetadata(LLVMContext::MD_associated)) { |
687 |
GO->getMetadata(LLVMContext::MD_associated)) { |
| 688 |
Check(Associated->getNumOperands() == 1, |
688 |
Check(Associated->getNumOperands() == 1, |
| 689 |
"associated metadata must have one operand", &GV, Associated); |
689 |
"associated metadata must have one operand", &GV, Associated); |
| 690 |
const Metadata *Op = Associated->getOperand(0).get(); |
690 |
const Metadata *Op = Associated->getOperand(0).get(); |
| 691 |
Check(Op, "associated metadata must have a global value", GO, Associated); |
691 |
Check(Op, "associated metadata must have a global value", GO, Associated); |
| 692 |
|
692 |
|
| 693 |
const auto *VM = dyn_cast_or_null(Op); |
693 |
const auto *VM = dyn_cast_or_null(Op); |
| 694 |
Check(VM, "associated metadata must be ValueAsMetadata", GO, Associated); |
694 |
Check(VM, "associated metadata must be ValueAsMetadata", GO, Associated); |
| 695 |
if (VM) { |
695 |
if (VM) { |
| 696 |
Check(isa(VM->getValue()->getType()), |
696 |
Check(isa(VM->getValue()->getType()), |
| 697 |
"associated value must be pointer typed", GV, Associated); |
697 |
"associated value must be pointer typed", GV, Associated); |
| 698 |
|
698 |
|
| 699 |
const Value *Stripped = VM->getValue()->stripPointerCastsAndAliases(); |
699 |
const Value *Stripped = VM->getValue()->stripPointerCastsAndAliases(); |
| 700 |
Check(isa(Stripped) || isa(Stripped), |
700 |
Check(isa(Stripped) || isa(Stripped), |
| 701 |
"associated metadata must point to a GlobalObject", GO, Stripped); |
701 |
"associated metadata must point to a GlobalObject", GO, Stripped); |
| 702 |
Check(Stripped != GO, |
702 |
Check(Stripped != GO, |
| 703 |
"global values should not associate to themselves", GO, |
703 |
"global values should not associate to themselves", GO, |
| 704 |
Associated); |
704 |
Associated); |
| 705 |
} |
705 |
} |
| 706 |
} |
706 |
} |
| 707 |
|
707 |
|
| 708 |
// FIXME: Why is getMetadata on GlobalValue protected? |
708 |
// FIXME: Why is getMetadata on GlobalValue protected? |
| 709 |
if (const MDNode *AbsoluteSymbol = |
709 |
if (const MDNode *AbsoluteSymbol = |
| 710 |
GO->getMetadata(LLVMContext::MD_absolute_symbol)) { |
710 |
GO->getMetadata(LLVMContext::MD_absolute_symbol)) { |
| 711 |
verifyRangeMetadata(*GO, AbsoluteSymbol, DL.getIntPtrType(GO->getType()), |
711 |
verifyRangeMetadata(*GO, AbsoluteSymbol, DL.getIntPtrType(GO->getType()), |
| 712 |
true); |
712 |
true); |
| 713 |
} |
713 |
} |
| 714 |
} |
714 |
} |
| 715 |
|
715 |
|
| 716 |
Check(!GV.hasAppendingLinkage() || isa(GV), |
716 |
Check(!GV.hasAppendingLinkage() || isa(GV), |
| 717 |
"Only global variables can have appending linkage!", &GV); |
717 |
"Only global variables can have appending linkage!", &GV); |
| 718 |
|
718 |
|
| 719 |
if (GV.hasAppendingLinkage()) { |
719 |
if (GV.hasAppendingLinkage()) { |
| 720 |
const GlobalVariable *GVar = dyn_cast(&GV); |
720 |
const GlobalVariable *GVar = dyn_cast(&GV); |
| 721 |
Check(GVar && GVar->getValueType()->isArrayTy(), |
721 |
Check(GVar && GVar->getValueType()->isArrayTy(), |
| 722 |
"Only global arrays can have appending linkage!", GVar); |
722 |
"Only global arrays can have appending linkage!", GVar); |
| 723 |
} |
723 |
} |
| 724 |
|
724 |
|
| 725 |
if (GV.isDeclarationForLinker()) |
725 |
if (GV.isDeclarationForLinker()) |
| 726 |
Check(!GV.hasComdat(), "Declaration may not be in a Comdat!", &GV); |
726 |
Check(!GV.hasComdat(), "Declaration may not be in a Comdat!", &GV); |
| 727 |
|
727 |
|
| 728 |
if (GV.hasDLLExportStorageClass()) { |
728 |
if (GV.hasDLLExportStorageClass()) { |
| 729 |
Check(!GV.hasHiddenVisibility(), |
729 |
Check(!GV.hasHiddenVisibility(), |
| 730 |
"dllexport GlobalValue must have default or protected visibility", |
730 |
"dllexport GlobalValue must have default or protected visibility", |
| 731 |
&GV); |
731 |
&GV); |
| 732 |
} |
732 |
} |
| 733 |
if (GV.hasDLLImportStorageClass()) { |
733 |
if (GV.hasDLLImportStorageClass()) { |
| 734 |
Check(GV.hasDefaultVisibility(), |
734 |
Check(GV.hasDefaultVisibility(), |
| 735 |
"dllimport GlobalValue must have default visibility", &GV); |
735 |
"dllimport GlobalValue must have default visibility", &GV); |
| 736 |
Check(!GV.isDSOLocal(), "GlobalValue with DLLImport Storage is dso_local!", |
736 |
Check(!GV.isDSOLocal(), "GlobalValue with DLLImport Storage is dso_local!", |
| 737 |
&GV); |
737 |
&GV); |
| 738 |
|
738 |
|
| 739 |
Check((GV.isDeclaration() && |
739 |
Check((GV.isDeclaration() && |
| 740 |
(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage())) || |
740 |
(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage())) || |
| 741 |
GV.hasAvailableExternallyLinkage(), |
741 |
GV.hasAvailableExternallyLinkage(), |
| 742 |
"Global is marked as dllimport, but not external", &GV); |
742 |
"Global is marked as dllimport, but not external", &GV); |
| 743 |
} |
743 |
} |
| 744 |
|
744 |
|
| 745 |
if (GV.isImplicitDSOLocal()) |
745 |
if (GV.isImplicitDSOLocal()) |
| 746 |
Check(GV.isDSOLocal(), |
746 |
Check(GV.isDSOLocal(), |
| 747 |
"GlobalValue with local linkage or non-default " |
747 |
"GlobalValue with local linkage or non-default " |
| 748 |
"visibility must be dso_local!", |
748 |
"visibility must be dso_local!", |
| 749 |
&GV); |
749 |
&GV); |
| 750 |
|
750 |
|
| 751 |
forEachUser(&GV, GlobalValueVisited, [&](const Value *V) -> bool { |
751 |
forEachUser(&GV, GlobalValueVisited, [&](const Value *V) -> bool { |
| 752 |
if (const Instruction *I = dyn_cast(V)) { |
752 |
if (const Instruction *I = dyn_cast(V)) { |
| 753 |
if (!I->getParent() || !I->getParent()->getParent()) |
753 |
if (!I->getParent() || !I->getParent()->getParent()) |
| 754 |
CheckFailed("Global is referenced by parentless instruction!", &GV, &M, |
754 |
CheckFailed("Global is referenced by parentless instruction!", &GV, &M, |
| 755 |
I); |
755 |
I); |
| 756 |
else if (I->getParent()->getParent()->getParent() != &M) |
756 |
else if (I->getParent()->getParent()->getParent() != &M) |
| 757 |
CheckFailed("Global is referenced in a different module!", &GV, &M, I, |
757 |
CheckFailed("Global is referenced in a different module!", &GV, &M, I, |
| 758 |
I->getParent()->getParent(), |
758 |
I->getParent()->getParent(), |
| 759 |
I->getParent()->getParent()->getParent()); |
759 |
I->getParent()->getParent()->getParent()); |
| 760 |
return false; |
760 |
return false; |
| 761 |
} else if (const Function *F = dyn_cast(V)) { |
761 |
} else if (const Function *F = dyn_cast(V)) { |
| 762 |
if (F->getParent() != &M) |
762 |
if (F->getParent() != &M) |
| 763 |
CheckFailed("Global is used by function in a different module", &GV, &M, |
763 |
CheckFailed("Global is used by function in a different module", &GV, &M, |
| 764 |
F, F->getParent()); |
764 |
F, F->getParent()); |
| 765 |
return false; |
765 |
return false; |
| 766 |
} |
766 |
} |
| 767 |
return true; |
767 |
return true; |
| 768 |
}); |
768 |
}); |
| 769 |
} |
769 |
} |
| 770 |
|
770 |
|
| 771 |
void Verifier::visitGlobalVariable(const GlobalVariable &GV) { |
771 |
void Verifier::visitGlobalVariable(const GlobalVariable &GV) { |
| 772 |
if (GV.hasInitializer()) { |
772 |
if (GV.hasInitializer()) { |
| 773 |
Check(GV.getInitializer()->getType() == GV.getValueType(), |
773 |
Check(GV.getInitializer()->getType() == GV.getValueType(), |
| 774 |
"Global variable initializer type does not match global " |
774 |
"Global variable initializer type does not match global " |
| 775 |
"variable type!", |
775 |
"variable type!", |
| 776 |
&GV); |
776 |
&GV); |
| 777 |
// If the global has common linkage, it must have a zero initializer and |
777 |
// If the global has common linkage, it must have a zero initializer and |
| 778 |
// cannot be constant. |
778 |
// cannot be constant. |
| 779 |
if (GV.hasCommonLinkage()) { |
779 |
if (GV.hasCommonLinkage()) { |
| 780 |
Check(GV.getInitializer()->isNullValue(), |
780 |
Check(GV.getInitializer()->isNullValue(), |
| 781 |
"'common' global must have a zero initializer!", &GV); |
781 |
"'common' global must have a zero initializer!", &GV); |
| 782 |
Check(!GV.isConstant(), "'common' global may not be marked constant!", |
782 |
Check(!GV.isConstant(), "'common' global may not be marked constant!", |
| 783 |
&GV); |
783 |
&GV); |
| 784 |
Check(!GV.hasComdat(), "'common' global may not be in a Comdat!", &GV); |
784 |
Check(!GV.hasComdat(), "'common' global may not be in a Comdat!", &GV); |
| 785 |
} |
785 |
} |
| 786 |
} |
786 |
} |
| 787 |
|
787 |
|
| 788 |
if (GV.hasName() && (GV.getName() == "llvm.global_ctors" || |
788 |
if (GV.hasName() && (GV.getName() == "llvm.global_ctors" || |
| 789 |
GV.getName() == "llvm.global_dtors")) { |
789 |
GV.getName() == "llvm.global_dtors")) { |
| 790 |
Check(!GV.hasInitializer() || GV.hasAppendingLinkage(), |
790 |
Check(!GV.hasInitializer() || GV.hasAppendingLinkage(), |
| 791 |
"invalid linkage for intrinsic global variable", &GV); |
791 |
"invalid linkage for intrinsic global variable", &GV); |
| 792 |
Check(GV.materialized_use_empty(), |
792 |
Check(GV.materialized_use_empty(), |
| 793 |
"invalid uses of intrinsic global variable", &GV); |
793 |
"invalid uses of intrinsic global variable", &GV); |
| 794 |
|
794 |
|
| 795 |
// Don't worry about emitting an error for it not being an array, |
795 |
// Don't worry about emitting an error for it not being an array, |
| 796 |
// visitGlobalValue will complain on appending non-array. |
796 |
// visitGlobalValue will complain on appending non-array. |
| 797 |
if (ArrayType *ATy = dyn_cast(GV.getValueType())) { |
797 |
if (ArrayType *ATy = dyn_cast(GV.getValueType())) { |
| 798 |
StructType *STy = dyn_cast(ATy->getElementType()); |
798 |
StructType *STy = dyn_cast(ATy->getElementType()); |
| 799 |
PointerType *FuncPtrTy = |
799 |
PointerType *FuncPtrTy = |
| 800 |
FunctionType::get(Type::getVoidTy(Context), false)-> |
800 |
FunctionType::get(Type::getVoidTy(Context), false)-> |
| 801 |
getPointerTo(DL.getProgramAddressSpace()); |
801 |
getPointerTo(DL.getProgramAddressSpace()); |
| 802 |
Check(STy && (STy->getNumElements() == 2 || STy->getNumElements() == 3) && |
802 |
Check(STy && (STy->getNumElements() == 2 || STy->getNumElements() == 3) && |
| 803 |
STy->getTypeAtIndex(0u)->isIntegerTy(32) && |
803 |
STy->getTypeAtIndex(0u)->isIntegerTy(32) && |
| 804 |
STy->getTypeAtIndex(1) == FuncPtrTy, |
804 |
STy->getTypeAtIndex(1) == FuncPtrTy, |
| 805 |
"wrong type for intrinsic global variable", &GV); |
805 |
"wrong type for intrinsic global variable", &GV); |
| 806 |
Check(STy->getNumElements() == 3, |
806 |
Check(STy->getNumElements() == 3, |
| 807 |
"the third field of the element type is mandatory, " |
807 |
"the third field of the element type is mandatory, " |
| 808 |
"specify ptr null to migrate from the obsoleted 2-field form"); |
808 |
"specify ptr null to migrate from the obsoleted 2-field form"); |
| 809 |
Type *ETy = STy->getTypeAtIndex(2); |
809 |
Type *ETy = STy->getTypeAtIndex(2); |
| 810 |
Check(ETy->isPointerTy(), "wrong type for intrinsic global variable", |
810 |
Check(ETy->isPointerTy(), "wrong type for intrinsic global variable", |
| 811 |
&GV); |
811 |
&GV); |
| 812 |
} |
812 |
} |
| 813 |
} |
813 |
} |
| 814 |
|
814 |
|
| 815 |
if (GV.hasName() && (GV.getName() == "llvm.used" || |
815 |
if (GV.hasName() && (GV.getName() == "llvm.used" || |
| 816 |
GV.getName() == "llvm.compiler.used")) { |
816 |
GV.getName() == "llvm.compiler.used")) { |
| 817 |
Check(!GV.hasInitializer() || GV.hasAppendingLinkage(), |
817 |
Check(!GV.hasInitializer() || GV.hasAppendingLinkage(), |
| 818 |
"invalid linkage for intrinsic global variable", &GV); |
818 |
"invalid linkage for intrinsic global variable", &GV); |
| 819 |
Check(GV.materialized_use_empty(), |
819 |
Check(GV.materialized_use_empty(), |
| 820 |
"invalid uses of intrinsic global variable", &GV); |
820 |
"invalid uses of intrinsic global variable", &GV); |
| 821 |
|
821 |
|
| 822 |
Type *GVType = GV.getValueType(); |
822 |
Type *GVType = GV.getValueType(); |
| 823 |
if (ArrayType *ATy = dyn_cast(GVType)) { |
823 |
if (ArrayType *ATy = dyn_cast(GVType)) { |
| 824 |
PointerType *PTy = dyn_cast(ATy->getElementType()); |
824 |
PointerType *PTy = dyn_cast(ATy->getElementType()); |
| 825 |
Check(PTy, "wrong type for intrinsic global variable", &GV); |
825 |
Check(PTy, "wrong type for intrinsic global variable", &GV); |
| 826 |
if (GV.hasInitializer()) { |
826 |
if (GV.hasInitializer()) { |
| 827 |
const Constant *Init = GV.getInitializer(); |
827 |
const Constant *Init = GV.getInitializer(); |
| 828 |
const ConstantArray *InitArray = dyn_cast(Init); |
828 |
const ConstantArray *InitArray = dyn_cast(Init); |
| 829 |
Check(InitArray, "wrong initalizer for intrinsic global variable", |
829 |
Check(InitArray, "wrong initalizer for intrinsic global variable", |
| 830 |
Init); |
830 |
Init); |
| 831 |
for (Value *Op : InitArray->operands()) { |
831 |
for (Value *Op : InitArray->operands()) { |
| 832 |
Value *V = Op->stripPointerCasts(); |
832 |
Value *V = Op->stripPointerCasts(); |
| 833 |
Check(isa(V) || isa(V) || |
833 |
Check(isa(V) || isa(V) || |
| 834 |
isa(V), |
834 |
isa(V), |
| 835 |
Twine("invalid ") + GV.getName() + " member", V); |
835 |
Twine("invalid ") + GV.getName() + " member", V); |
| 836 |
Check(V->hasName(), |
836 |
Check(V->hasName(), |
| 837 |
Twine("members of ") + GV.getName() + " must be named", V); |
837 |
Twine("members of ") + GV.getName() + " must be named", V); |
| 838 |
} |
838 |
} |
| 839 |
} |
839 |
} |
| 840 |
} |
840 |
} |
| 841 |
} |
841 |
} |
| 842 |
|
842 |
|
| 843 |
// Visit any debug info attachments. |
843 |
// Visit any debug info attachments. |
| 844 |
SmallVector MDs; |
844 |
SmallVector MDs; |
| 845 |
GV.getMetadata(LLVMContext::MD_dbg, MDs); |
845 |
GV.getMetadata(LLVMContext::MD_dbg, MDs); |
| 846 |
for (auto *MD : MDs) { |
846 |
for (auto *MD : MDs) { |
| 847 |
if (auto *GVE = dyn_cast(MD)) |
847 |
if (auto *GVE = dyn_cast(MD)) |
| 848 |
visitDIGlobalVariableExpression(*GVE); |
848 |
visitDIGlobalVariableExpression(*GVE); |
| 849 |
else |
849 |
else |
| 850 |
CheckDI(false, "!dbg attachment of global variable must be a " |
850 |
CheckDI(false, "!dbg attachment of global variable must be a " |
| 851 |
"DIGlobalVariableExpression"); |
851 |
"DIGlobalVariableExpression"); |
| 852 |
} |
852 |
} |
| 853 |
|
853 |
|
| 854 |
// Scalable vectors cannot be global variables, since we don't know |
854 |
// Scalable vectors cannot be global variables, since we don't know |
| 855 |
// the runtime size. If the global is an array containing scalable vectors, |
855 |
// the runtime size. If the global is an array containing scalable vectors, |
| 856 |
// that will be caught by the isValidElementType methods in StructType or |
856 |
// that will be caught by the isValidElementType methods in StructType or |
| 857 |
// ArrayType instead. |
857 |
// ArrayType instead. |
| 858 |
Check(!isa(GV.getValueType()), |
858 |
Check(!isa(GV.getValueType()), |
| 859 |
"Globals cannot contain scalable vectors", &GV); |
859 |
"Globals cannot contain scalable vectors", &GV); |
| 860 |
|
860 |
|
| 861 |
if (auto *STy = dyn_cast(GV.getValueType())) { |
861 |
if (auto *STy = dyn_cast(GV.getValueType())) { |
| 862 |
SmallPtrSet Visited; |
862 |
SmallPtrSet Visited; |
| 863 |
Check(!STy->containsScalableVectorType(&Visited), |
863 |
Check(!STy->containsScalableVectorType(&Visited), |
| 864 |
"Globals cannot contain scalable vectors", &GV); |
864 |
"Globals cannot contain scalable vectors", &GV); |
| 865 |
} |
865 |
} |
| 866 |
|
866 |
|
| 867 |
// Check if it's a target extension type that disallows being used as a |
867 |
// Check if it's a target extension type that disallows being used as a |
| 868 |
// global. |
868 |
// global. |
| 869 |
if (auto *TTy = dyn_cast(GV.getValueType())) |
869 |
if (auto *TTy = dyn_cast(GV.getValueType())) |
| 870 |
Check(TTy->hasProperty(TargetExtType::CanBeGlobal), |
870 |
Check(TTy->hasProperty(TargetExtType::CanBeGlobal), |
| 871 |
"Global @" + GV.getName() + " has illegal target extension type", |
871 |
"Global @" + GV.getName() + " has illegal target extension type", |
| 872 |
TTy); |
872 |
TTy); |
| 873 |
|
873 |
|
| 874 |
if (!GV.hasInitializer()) { |
874 |
if (!GV.hasInitializer()) { |
| 875 |
visitGlobalValue(GV); |
875 |
visitGlobalValue(GV); |
| 876 |
return; |
876 |
return; |
| 877 |
} |
877 |
} |
| 878 |
|
878 |
|
| 879 |
// Walk any aggregate initializers looking for bitcasts between address spaces |
879 |
// Walk any aggregate initializers looking for bitcasts between address spaces |
| 880 |
visitConstantExprsRecursively(GV.getInitializer()); |
880 |
visitConstantExprsRecursively(GV.getInitializer()); |
| 881 |
|
881 |
|
| 882 |
visitGlobalValue(GV); |
882 |
visitGlobalValue(GV); |
| 883 |
} |
883 |
} |
| 884 |
|
884 |
|
| 885 |
void Verifier::visitAliaseeSubExpr(const GlobalAlias &GA, const Constant &C) { |
885 |
void Verifier::visitAliaseeSubExpr(const GlobalAlias &GA, const Constant &C) { |
| 886 |
SmallPtrSet Visited; |
886 |
SmallPtrSet Visited; |
| 887 |
Visited.insert(&GA); |
887 |
Visited.insert(&GA); |
| 888 |
visitAliaseeSubExpr(Visited, GA, C); |
888 |
visitAliaseeSubExpr(Visited, GA, C); |
| 889 |
} |
889 |
} |
| 890 |
|
890 |
|
| 891 |
void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl &Visited, |
891 |
void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl &Visited, |
| 892 |
const GlobalAlias &GA, const Constant &C) { |
892 |
const GlobalAlias &GA, const Constant &C) { |
| 893 |
if (GA.hasAvailableExternallyLinkage()) { |
893 |
if (GA.hasAvailableExternallyLinkage()) { |
| 894 |
Check(isa(C) && |
894 |
Check(isa(C) && |
| 895 |
cast(C).hasAvailableExternallyLinkage(), |
895 |
cast(C).hasAvailableExternallyLinkage(), |
| 896 |
"available_externally alias must point to available_externally " |
896 |
"available_externally alias must point to available_externally " |
| 897 |
"global value", |
897 |
"global value", |
| 898 |
&GA); |
898 |
&GA); |
| 899 |
} |
899 |
} |
| 900 |
if (const auto *GV = dyn_cast(&C)) { |
900 |
if (const auto *GV = dyn_cast(&C)) { |
| 901 |
if (!GA.hasAvailableExternallyLinkage()) { |
901 |
if (!GA.hasAvailableExternallyLinkage()) { |
| 902 |
Check(!GV->isDeclarationForLinker(), "Alias must point to a definition", |
902 |
Check(!GV->isDeclarationForLinker(), "Alias must point to a definition", |
| 903 |
&GA); |
903 |
&GA); |
| 904 |
} |
904 |
} |
| 905 |
|
905 |
|
| 906 |
if (const auto *GA2 = dyn_cast(GV)) { |
906 |
if (const auto *GA2 = dyn_cast(GV)) { |
| 907 |
Check(Visited.insert(GA2).second, "Aliases cannot form a cycle", &GA); |
907 |
Check(Visited.insert(GA2).second, "Aliases cannot form a cycle", &GA); |
| 908 |
|
908 |
|
| 909 |
Check(!GA2->isInterposable(), |
909 |
Check(!GA2->isInterposable(), |
| 910 |
"Alias cannot point to an interposable alias", &GA); |
910 |
"Alias cannot point to an interposable alias", &GA); |
| 911 |
} else { |
911 |
} else { |
| 912 |
// Only continue verifying subexpressions of GlobalAliases. |
912 |
// Only continue verifying subexpressions of GlobalAliases. |
| 913 |
// Do not recurse into global initializers. |
913 |
// Do not recurse into global initializers. |
| 914 |
return; |
914 |
return; |
| 915 |
} |
915 |
} |
| 916 |
} |
916 |
} |
| 917 |
|
917 |
|
| 918 |
if (const auto *CE = dyn_cast(&C)) |
918 |
if (const auto *CE = dyn_cast(&C)) |
| 919 |
visitConstantExprsRecursively(CE); |
919 |
visitConstantExprsRecursively(CE); |
| 920 |
|
920 |
|
| 921 |
for (const Use &U : C.operands()) { |
921 |
for (const Use &U : C.operands()) { |
| 922 |
Value *V = &*U; |
922 |
Value *V = &*U; |
| 923 |
if (const auto *GA2 = dyn_cast(V)) |
923 |
if (const auto *GA2 = dyn_cast(V)) |
| 924 |
visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee()); |
924 |
visitAliaseeSubExpr(Visited, GA, *GA2->getAliasee()); |
| 925 |
else if (const auto *C2 = dyn_cast(V)) |
925 |
else if (const auto *C2 = dyn_cast(V)) |
| 926 |
visitAliaseeSubExpr(Visited, GA, *C2); |
926 |
visitAliaseeSubExpr(Visited, GA, *C2); |
| 927 |
} |
927 |
} |
| 928 |
} |
928 |
} |
| 929 |
|
929 |
|
| 930 |
void Verifier::visitGlobalAlias(const GlobalAlias &GA) { |
930 |
void Verifier::visitGlobalAlias(const GlobalAlias &GA) { |
| 931 |
Check(GlobalAlias::isValidLinkage(GA.getLinkage()), |
931 |
Check(GlobalAlias::isValidLinkage(GA.getLinkage()), |
| 932 |
"Alias should have private, internal, linkonce, weak, linkonce_odr, " |
932 |
"Alias should have private, internal, linkonce, weak, linkonce_odr, " |
| 933 |
"weak_odr, external, or available_externally linkage!", |
933 |
"weak_odr, external, or available_externally linkage!", |
| 934 |
&GA); |
934 |
&GA); |
| 935 |
const Constant *Aliasee = GA.getAliasee(); |
935 |
const Constant *Aliasee = GA.getAliasee(); |
| 936 |
Check(Aliasee, "Aliasee cannot be NULL!", &GA); |
936 |
Check(Aliasee, "Aliasee cannot be NULL!", &GA); |
| 937 |
Check(GA.getType() == Aliasee->getType(), |
937 |
Check(GA.getType() == Aliasee->getType(), |
| 938 |
"Alias and aliasee types should match!", &GA); |
938 |
"Alias and aliasee types should match!", &GA); |
| 939 |
|
939 |
|
| 940 |
Check(isa(Aliasee) || isa(Aliasee), |
940 |
Check(isa(Aliasee) || isa(Aliasee), |
| 941 |
"Aliasee should be either GlobalValue or ConstantExpr", &GA); |
941 |
"Aliasee should be either GlobalValue or ConstantExpr", &GA); |
| 942 |
|
942 |
|
| 943 |
visitAliaseeSubExpr(GA, *Aliasee); |
943 |
visitAliaseeSubExpr(GA, *Aliasee); |
| 944 |
|
944 |
|
| 945 |
visitGlobalValue(GA); |
945 |
visitGlobalValue(GA); |
| 946 |
} |
946 |
} |
| 947 |
|
947 |
|
| 948 |
void Verifier::visitGlobalIFunc(const GlobalIFunc &GI) { |
948 |
void Verifier::visitGlobalIFunc(const GlobalIFunc &GI) { |
| 949 |
Check(GlobalIFunc::isValidLinkage(GI.getLinkage()), |
949 |
Check(GlobalIFunc::isValidLinkage(GI.getLinkage()), |
| 950 |
"IFunc should have private, internal, linkonce, weak, linkonce_odr, " |
950 |
"IFunc should have private, internal, linkonce, weak, linkonce_odr, " |
| 951 |
"weak_odr, or external linkage!", |
951 |
"weak_odr, or external linkage!", |
| 952 |
&GI); |
952 |
&GI); |
| 953 |
// Pierce through ConstantExprs and GlobalAliases and check that the resolver |
953 |
// Pierce through ConstantExprs and GlobalAliases and check that the resolver |
| 954 |
// is a Function definition. |
954 |
// is a Function definition. |
| 955 |
const Function *Resolver = GI.getResolverFunction(); |
955 |
const Function *Resolver = GI.getResolverFunction(); |
| 956 |
Check(Resolver, "IFunc must have a Function resolver", &GI); |
956 |
Check(Resolver, "IFunc must have a Function resolver", &GI); |
| 957 |
Check(!Resolver->isDeclarationForLinker(), |
957 |
Check(!Resolver->isDeclarationForLinker(), |
| 958 |
"IFunc resolver must be a definition", &GI); |
958 |
"IFunc resolver must be a definition", &GI); |
| 959 |
|
959 |
|
| 960 |
// Check that the immediate resolver operand (prior to any bitcasts) has the |
960 |
// Check that the immediate resolver operand (prior to any bitcasts) has the |
| 961 |
// correct type. |
961 |
// correct type. |
| 962 |
const Type *ResolverTy = GI.getResolver()->getType(); |
962 |
const Type *ResolverTy = GI.getResolver()->getType(); |
| 963 |
|
963 |
|
| 964 |
Check(isa(Resolver->getFunctionType()->getReturnType()), |
964 |
Check(isa(Resolver->getFunctionType()->getReturnType()), |
| 965 |
"IFunc resolver must return a pointer", &GI); |
965 |
"IFunc resolver must return a pointer", &GI); |
| 966 |
|
966 |
|
| 967 |
const Type *ResolverFuncTy = |
967 |
const Type *ResolverFuncTy = |
| 968 |
GlobalIFunc::getResolverFunctionType(GI.getValueType()); |
968 |
GlobalIFunc::getResolverFunctionType(GI.getValueType()); |
| 969 |
Check(ResolverTy == ResolverFuncTy->getPointerTo(GI.getAddressSpace()), |
969 |
Check(ResolverTy == ResolverFuncTy->getPointerTo(GI.getAddressSpace()), |
| 970 |
"IFunc resolver has incorrect type", &GI); |
970 |
"IFunc resolver has incorrect type", &GI); |
| 971 |
} |
971 |
} |
| 972 |
|
972 |
|
| 973 |
void Verifier::visitNamedMDNode(const NamedMDNode &NMD) { |
973 |
void Verifier::visitNamedMDNode(const NamedMDNode &NMD) { |
| 974 |
// There used to be various other llvm.dbg.* nodes, but we don't support |
974 |
// There used to be various other llvm.dbg.* nodes, but we don't support |
| 975 |
// upgrading them and we want to reserve the namespace for future uses. |
975 |
// upgrading them and we want to reserve the namespace for future uses. |
| 976 |
if (NMD.getName().startswith("llvm.dbg.")) |
976 |
if (NMD.getName().startswith("llvm.dbg.")) |
| 977 |
CheckDI(NMD.getName() == "llvm.dbg.cu", |
977 |
CheckDI(NMD.getName() == "llvm.dbg.cu", |
| 978 |
"unrecognized named metadata node in the llvm.dbg namespace", &NMD); |
978 |
"unrecognized named metadata node in the llvm.dbg namespace", &NMD); |
| 979 |
for (const MDNode *MD : NMD.operands()) { |
979 |
for (const MDNode *MD : NMD.operands()) { |
| 980 |
if (NMD.getName() == "llvm.dbg.cu") |
980 |
if (NMD.getName() == "llvm.dbg.cu") |
| 981 |
CheckDI(MD && isa(MD), "invalid compile unit", &NMD, MD); |
981 |
CheckDI(MD && isa(MD), "invalid compile unit", &NMD, MD); |
| 982 |
|
982 |
|
| 983 |
if (!MD) |
983 |
if (!MD) |
| 984 |
continue; |
984 |
continue; |
| 985 |
|
985 |
|
| 986 |
visitMDNode(*MD, AreDebugLocsAllowed::Yes); |
986 |
visitMDNode(*MD, AreDebugLocsAllowed::Yes); |
| 987 |
} |
987 |
} |
| 988 |
} |
988 |
} |
| 989 |
|
989 |
|
| 990 |
void Verifier::visitMDNode(const MDNode &MD, AreDebugLocsAllowed AllowLocs) { |
990 |
void Verifier::visitMDNode(const MDNode &MD, AreDebugLocsAllowed AllowLocs) { |
| 991 |
// Only visit each node once. Metadata can be mutually recursive, so this |
991 |
// Only visit each node once. Metadata can be mutually recursive, so this |
| 992 |
// avoids infinite recursion here, as well as being an optimization. |
992 |
// avoids infinite recursion here, as well as being an optimization. |
| 993 |
if (!MDNodes.insert(&MD).second) |
993 |
if (!MDNodes.insert(&MD).second) |
| 994 |
return; |
994 |
return; |
| 995 |
|
995 |
|
| 996 |
Check(&MD.getContext() == &Context, |
996 |
Check(&MD.getContext() == &Context, |
| 997 |
"MDNode context does not match Module context!", &MD); |
997 |
"MDNode context does not match Module context!", &MD); |
| 998 |
|
998 |
|
| 999 |
switch (MD.getMetadataID()) { |
999 |
switch (MD.getMetadataID()) { |
| 1000 |
default: |
1000 |
default: |
| 1001 |
llvm_unreachable("Invalid MDNode subclass"); |
1001 |
llvm_unreachable("Invalid MDNode subclass"); |
| 1002 |
case Metadata::MDTupleKind: |
1002 |
case Metadata::MDTupleKind: |
| 1003 |
break; |
1003 |
break; |
| 1004 |
#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ |
1004 |
#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ |
| 1005 |
case Metadata::CLASS##Kind: \ |
1005 |
case Metadata::CLASS##Kind: \ |
| 1006 |
visit##CLASS(cast(MD)); \ |
1006 |
visit##CLASS(cast(MD)); \ |
| 1007 |
break; |
1007 |
break; |
| 1008 |
#include "llvm/IR/Metadata.def" |
1008 |
#include "llvm/IR/Metadata.def" |
| 1009 |
} |
1009 |
} |
| 1010 |
|
1010 |
|
| 1011 |
for (const Metadata *Op : MD.operands()) { |
1011 |
for (const Metadata *Op : MD.operands()) { |
| 1012 |
if (!Op) |
1012 |
if (!Op) |
| 1013 |
continue; |
1013 |
continue; |
| 1014 |
Check(!isa(Op), "Invalid operand for global metadata!", |
1014 |
Check(!isa(Op), "Invalid operand for global metadata!", |
| 1015 |
&MD, Op); |
1015 |
&MD, Op); |
| 1016 |
CheckDI(!isa(Op) || AllowLocs == AreDebugLocsAllowed::Yes, |
1016 |
CheckDI(!isa(Op) || AllowLocs == AreDebugLocsAllowed::Yes, |
| 1017 |
"DILocation not allowed within this metadata node", &MD, Op); |
1017 |
"DILocation not allowed within this metadata node", &MD, Op); |
| 1018 |
if (auto *N = dyn_cast(Op)) { |
1018 |
if (auto *N = dyn_cast(Op)) { |
| 1019 |
visitMDNode(*N, AllowLocs); |
1019 |
visitMDNode(*N, AllowLocs); |
| 1020 |
continue; |
1020 |
continue; |
| 1021 |
} |
1021 |
} |
| 1022 |
if (auto *V = dyn_cast(Op)) { |
1022 |
if (auto *V = dyn_cast(Op)) { |
| 1023 |
visitValueAsMetadata(*V, nullptr); |
1023 |
visitValueAsMetadata(*V, nullptr); |
| 1024 |
continue; |
1024 |
continue; |
| 1025 |
} |
1025 |
} |
| 1026 |
} |
1026 |
} |
| 1027 |
|
1027 |
|
| 1028 |
// Check these last, so we diagnose problems in operands first. |
1028 |
// Check these last, so we diagnose problems in operands first. |
| 1029 |
Check(!MD.isTemporary(), "Expected no forward declarations!", &MD); |
1029 |
Check(!MD.isTemporary(), "Expected no forward declarations!", &MD); |
| 1030 |
Check(MD.isResolved(), "All nodes should be resolved!", &MD); |
1030 |
Check(MD.isResolved(), "All nodes should be resolved!", &MD); |
| 1031 |
} |
1031 |
} |
| 1032 |
|
1032 |
|
| 1033 |
void Verifier::visitValueAsMetadata(const ValueAsMetadata &MD, Function *F) { |
1033 |
void Verifier::visitValueAsMetadata(const ValueAsMetadata &MD, Function *F) { |
| 1034 |
Check(MD.getValue(), "Expected valid value", &MD); |
1034 |
Check(MD.getValue(), "Expected valid value", &MD); |
| 1035 |
Check(!MD.getValue()->getType()->isMetadataTy(), |
1035 |
Check(!MD.getValue()->getType()->isMetadataTy(), |
| 1036 |
"Unexpected metadata round-trip through values", &MD, MD.getValue()); |
1036 |
"Unexpected metadata round-trip through values", &MD, MD.getValue()); |
| 1037 |
|
1037 |
|
| 1038 |
auto *L = dyn_cast(&MD); |
1038 |
auto *L = dyn_cast(&MD); |
| 1039 |
if (!L) |
1039 |
if (!L) |
| 1040 |
return; |
1040 |
return; |
| 1041 |
|
1041 |
|
| 1042 |
Check(F, "function-local metadata used outside a function", L); |
1042 |
Check(F, "function-local metadata used outside a function", L); |
| 1043 |
|
1043 |
|
| 1044 |
// If this was an instruction, bb, or argument, verify that it is in the |
1044 |
// If this was an instruction, bb, or argument, verify that it is in the |
| 1045 |
// function that we expect. |
1045 |
// function that we expect. |
| 1046 |
Function *ActualF = nullptr; |
1046 |
Function *ActualF = nullptr; |
| 1047 |
if (Instruction *I = dyn_cast(L->getValue())) { |
1047 |
if (Instruction *I = dyn_cast(L->getValue())) { |
| 1048 |
Check(I->getParent(), "function-local metadata not in basic block", L, I); |
1048 |
Check(I->getParent(), "function-local metadata not in basic block", L, I); |
| 1049 |
ActualF = I->getParent()->getParent(); |
1049 |
ActualF = I->getParent()->getParent(); |
| 1050 |
} else if (BasicBlock *BB = dyn_cast(L->getValue())) |
1050 |
} else if (BasicBlock *BB = dyn_cast(L->getValue())) |
| 1051 |
ActualF = BB->getParent(); |
1051 |
ActualF = BB->getParent(); |
| 1052 |
else if (Argument *A = dyn_cast(L->getValue())) |
1052 |
else if (Argument *A = dyn_cast(L->getValue())) |
| 1053 |
ActualF = A->getParent(); |
1053 |
ActualF = A->getParent(); |
| 1054 |
assert(ActualF && "Unimplemented function local metadata case!"); |
1054 |
assert(ActualF && "Unimplemented function local metadata case!"); |
| 1055 |
|
1055 |
|
| 1056 |
Check(ActualF == F, "function-local metadata used in wrong function", L); |
1056 |
Check(ActualF == F, "function-local metadata used in wrong function", L); |
| 1057 |
} |
1057 |
} |
| 1058 |
|
1058 |
|
| 1059 |
void Verifier::visitMetadataAsValue(const MetadataAsValue &MDV, Function *F) { |
1059 |
void Verifier::visitMetadataAsValue(const MetadataAsValue &MDV, Function *F) { |
| 1060 |
Metadata *MD = MDV.getMetadata(); |
1060 |
Metadata *MD = MDV.getMetadata(); |
| 1061 |
if (auto *N = dyn_cast(MD)) { |
1061 |
if (auto *N = dyn_cast(MD)) { |
| 1062 |
visitMDNode(*N, AreDebugLocsAllowed::No); |
1062 |
visitMDNode(*N, AreDebugLocsAllowed::No); |
| 1063 |
return; |
1063 |
return; |
| 1064 |
} |
1064 |
} |
| 1065 |
|
1065 |
|
| 1066 |
// Only visit each node once. Metadata can be mutually recursive, so this |
1066 |
// Only visit each node once. Metadata can be mutually recursive, so this |
| 1067 |
// avoids infinite recursion here, as well as being an optimization. |
1067 |
// avoids infinite recursion here, as well as being an optimization. |
| 1068 |
if (!MDNodes.insert(MD).second) |
1068 |
if (!MDNodes.insert(MD).second) |
| 1069 |
return; |
1069 |
return; |
| 1070 |
|
1070 |
|
| 1071 |
if (auto *V = dyn_cast(MD)) |
1071 |
if (auto *V = dyn_cast(MD)) |
| 1072 |
visitValueAsMetadata(*V, F); |
1072 |
visitValueAsMetadata(*V, F); |
| 1073 |
} |
1073 |
} |
| 1074 |
|
1074 |
|
| 1075 |
static bool isType(const Metadata *MD) { return !MD || isa(MD); } |
1075 |
static bool isType(const Metadata *MD) { return !MD || isa(MD); } |
| 1076 |
static bool isScope(const Metadata *MD) { return !MD || isa(MD); } |
1076 |
static bool isScope(const Metadata *MD) { return !MD || isa(MD); } |
| 1077 |
static bool isDINode(const Metadata *MD) { return !MD || isa(MD); } |
1077 |
static bool isDINode(const Metadata *MD) { return !MD || isa(MD); } |
| 1078 |
|
1078 |
|
| 1079 |
void Verifier::visitDILocation(const DILocation &N) { |
1079 |
void Verifier::visitDILocation(const DILocation &N) { |
| 1080 |
CheckDI(N.getRawScope() && isa(N.getRawScope()), |
1080 |
CheckDI(N.getRawScope() && isa(N.getRawScope()), |
| 1081 |
"location requires a valid scope", &N, N.getRawScope()); |
1081 |
"location requires a valid scope", &N, N.getRawScope()); |
| 1082 |
if (auto *IA = N.getRawInlinedAt()) |
1082 |
if (auto *IA = N.getRawInlinedAt()) |
| 1083 |
CheckDI(isa(IA), "inlined-at should be a location", &N, IA); |
1083 |
CheckDI(isa(IA), "inlined-at should be a location", &N, IA); |
| 1084 |
if (auto *SP = dyn_cast(N.getRawScope())) |
1084 |
if (auto *SP = dyn_cast(N.getRawScope())) |
| 1085 |
CheckDI(SP->isDefinition(), "scope points into the type hierarchy", &N); |
1085 |
CheckDI(SP->isDefinition(), "scope points into the type hierarchy", &N); |
| 1086 |
} |
1086 |
} |
| 1087 |
|
1087 |
|
| 1088 |
void Verifier::visitGenericDINode(const GenericDINode &N) { |
1088 |
void Verifier::visitGenericDINode(const GenericDINode &N) { |
| 1089 |
CheckDI(N.getTag(), "invalid tag", &N); |
1089 |
CheckDI(N.getTag(), "invalid tag", &N); |
| 1090 |
} |
1090 |
} |
| 1091 |
|
1091 |
|
| 1092 |
void Verifier::visitDIScope(const DIScope &N) { |
1092 |
void Verifier::visitDIScope(const DIScope &N) { |
| 1093 |
if (auto *F = N.getRawFile()) |
1093 |
if (auto *F = N.getRawFile()) |
| 1094 |
CheckDI(isa(F), "invalid file", &N, F); |
1094 |
CheckDI(isa(F), "invalid file", &N, F); |
| 1095 |
} |
1095 |
} |
| 1096 |
|
1096 |
|
| 1097 |
void Verifier::visitDISubrange(const DISubrange &N) { |
1097 |
void Verifier::visitDISubrange(const DISubrange &N) { |
| 1098 |
CheckDI(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N); |
1098 |
CheckDI(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N); |
| 1099 |
bool HasAssumedSizedArraySupport = dwarf::isFortran(CurrentSourceLang); |
1099 |
bool HasAssumedSizedArraySupport = dwarf::isFortran(CurrentSourceLang); |
| 1100 |
CheckDI(HasAssumedSizedArraySupport || N.getRawCountNode() || |
1100 |
CheckDI(HasAssumedSizedArraySupport || N.getRawCountNode() || |
| 1101 |
N.getRawUpperBound(), |
1101 |
N.getRawUpperBound(), |
| 1102 |
"Subrange must contain count or upperBound", &N); |
1102 |
"Subrange must contain count or upperBound", &N); |
| 1103 |
CheckDI(!N.getRawCountNode() || !N.getRawUpperBound(), |
1103 |
CheckDI(!N.getRawCountNode() || !N.getRawUpperBound(), |
| 1104 |
"Subrange can have any one of count or upperBound", &N); |
1104 |
"Subrange can have any one of count or upperBound", &N); |
| 1105 |
auto *CBound = N.getRawCountNode(); |
1105 |
auto *CBound = N.getRawCountNode(); |
| 1106 |
CheckDI(!CBound || isa(CBound) || |
1106 |
CheckDI(!CBound || isa(CBound) || |
| 1107 |
isa(CBound) || isa(CBound), |
1107 |
isa(CBound) || isa(CBound), |
| 1108 |
"Count must be signed constant or DIVariable or DIExpression", &N); |
1108 |
"Count must be signed constant or DIVariable or DIExpression", &N); |
| 1109 |
auto Count = N.getCount(); |
1109 |
auto Count = N.getCount(); |
| 1110 |
CheckDI(!Count || !isa(Count) || |
1110 |
CheckDI(!Count || !isa(Count) || |
| 1111 |
cast(Count)->getSExtValue() >= -1, |
1111 |
cast(Count)->getSExtValue() >= -1, |
| 1112 |
"invalid subrange count", &N); |
1112 |
"invalid subrange count", &N); |
| 1113 |
auto *LBound = N.getRawLowerBound(); |
1113 |
auto *LBound = N.getRawLowerBound(); |
| 1114 |
CheckDI(!LBound || isa(LBound) || |
1114 |
CheckDI(!LBound || isa(LBound) || |
| 1115 |
isa(LBound) || isa(LBound), |
1115 |
isa(LBound) || isa(LBound), |
| 1116 |
"LowerBound must be signed constant or DIVariable or DIExpression", |
1116 |
"LowerBound must be signed constant or DIVariable or DIExpression", |
| 1117 |
&N); |
1117 |
&N); |
| 1118 |
auto *UBound = N.getRawUpperBound(); |
1118 |
auto *UBound = N.getRawUpperBound(); |
| 1119 |
CheckDI(!UBound || isa(UBound) || |
1119 |
CheckDI(!UBound || isa(UBound) || |
| 1120 |
isa(UBound) || isa(UBound), |
1120 |
isa(UBound) || isa(UBound), |
| 1121 |
"UpperBound must be signed constant or DIVariable or DIExpression", |
1121 |
"UpperBound must be signed constant or DIVariable or DIExpression", |
| 1122 |
&N); |
1122 |
&N); |
| 1123 |
auto *Stride = N.getRawStride(); |
1123 |
auto *Stride = N.getRawStride(); |
| 1124 |
CheckDI(!Stride || isa(Stride) || |
1124 |
CheckDI(!Stride || isa(Stride) || |
| 1125 |
isa(Stride) || isa(Stride), |
1125 |
isa(Stride) || isa(Stride), |
| 1126 |
"Stride must be signed constant or DIVariable or DIExpression", &N); |
1126 |
"Stride must be signed constant or DIVariable or DIExpression", &N); |
| 1127 |
} |
1127 |
} |
| 1128 |
|
1128 |
|
| 1129 |
void Verifier::visitDIGenericSubrange(const DIGenericSubrange &N) { |
1129 |
void Verifier::visitDIGenericSubrange(const DIGenericSubrange &N) { |
| 1130 |
CheckDI(N.getTag() == dwarf::DW_TAG_generic_subrange, "invalid tag", &N); |
1130 |
CheckDI(N.getTag() == dwarf::DW_TAG_generic_subrange, "invalid tag", &N); |
| 1131 |
CheckDI(N.getRawCountNode() || N.getRawUpperBound(), |
1131 |
CheckDI(N.getRawCountNode() || N.getRawUpperBound(), |
| 1132 |
"GenericSubrange must contain count or upperBound", &N); |
1132 |
"GenericSubrange must contain count or upperBound", &N); |
| 1133 |
CheckDI(!N.getRawCountNode() || !N.getRawUpperBound(), |
1133 |
CheckDI(!N.getRawCountNode() || !N.getRawUpperBound(), |
| 1134 |
"GenericSubrange can have any one of count or upperBound", &N); |
1134 |
"GenericSubrange can have any one of count or upperBound", &N); |
| 1135 |
auto *CBound = N.getRawCountNode(); |
1135 |
auto *CBound = N.getRawCountNode(); |
| 1136 |
CheckDI(!CBound || isa(CBound) || isa(CBound), |
1136 |
CheckDI(!CBound || isa(CBound) || isa(CBound), |
| 1137 |
"Count must be signed constant or DIVariable or DIExpression", &N); |
1137 |
"Count must be signed constant or DIVariable or DIExpression", &N); |
| 1138 |
auto *LBound = N.getRawLowerBound(); |
1138 |
auto *LBound = N.getRawLowerBound(); |
| 1139 |
CheckDI(LBound, "GenericSubrange must contain lowerBound", &N); |
1139 |
CheckDI(LBound, "GenericSubrange must contain lowerBound", &N); |
| 1140 |
CheckDI(isa(LBound) || isa(LBound), |
1140 |
CheckDI(isa(LBound) || isa(LBound), |
| 1141 |
"LowerBound must be signed constant or DIVariable or DIExpression", |
1141 |
"LowerBound must be signed constant or DIVariable or DIExpression", |
| 1142 |
&N); |
1142 |
&N); |
| 1143 |
auto *UBound = N.getRawUpperBound(); |
1143 |
auto *UBound = N.getRawUpperBound(); |
| 1144 |
CheckDI(!UBound || isa(UBound) || isa(UBound), |
1144 |
CheckDI(!UBound || isa(UBound) || isa(UBound), |
| 1145 |
"UpperBound must be signed constant or DIVariable or DIExpression", |
1145 |
"UpperBound must be signed constant or DIVariable or DIExpression", |
| 1146 |
&N); |
1146 |
&N); |
| 1147 |
auto *Stride = N.getRawStride(); |
1147 |
auto *Stride = N.getRawStride(); |
| 1148 |
CheckDI(Stride, "GenericSubrange must contain stride", &N); |
1148 |
CheckDI(Stride, "GenericSubrange must contain stride", &N); |
| 1149 |
CheckDI(isa(Stride) || isa(Stride), |
1149 |
CheckDI(isa(Stride) || isa(Stride), |
| 1150 |
"Stride must be signed constant or DIVariable or DIExpression", &N); |
1150 |
"Stride must be signed constant or DIVariable or DIExpression", &N); |
| 1151 |
} |
1151 |
} |
| 1152 |
|
1152 |
|
| 1153 |
void Verifier::visitDIEnumerator(const DIEnumerator &N) { |
1153 |
void Verifier::visitDIEnumerator(const DIEnumerator &N) { |
| 1154 |
CheckDI(N.getTag() == dwarf::DW_TAG_enumerator, "invalid tag", &N); |
1154 |
CheckDI(N.getTag() == dwarf::DW_TAG_enumerator, "invalid tag", &N); |
| 1155 |
} |
1155 |
} |
| 1156 |
|
1156 |
|
| 1157 |
void Verifier::visitDIBasicType(const DIBasicType &N) { |
1157 |
void Verifier::visitDIBasicType(const DIBasicType &N) { |
| 1158 |
CheckDI(N.getTag() == dwarf::DW_TAG_base_type || |
1158 |
CheckDI(N.getTag() == dwarf::DW_TAG_base_type || |
| 1159 |
N.getTag() == dwarf::DW_TAG_unspecified_type || |
1159 |
N.getTag() == dwarf::DW_TAG_unspecified_type || |
| 1160 |
N.getTag() == dwarf::DW_TAG_string_type, |
1160 |
N.getTag() == dwarf::DW_TAG_string_type, |
| 1161 |
"invalid tag", &N); |
1161 |
"invalid tag", &N); |
| 1162 |
} |
1162 |
} |
| 1163 |
|
1163 |
|
| 1164 |
void Verifier::visitDIStringType(const DIStringType &N) { |
1164 |
void Verifier::visitDIStringType(const DIStringType &N) { |
| 1165 |
CheckDI(N.getTag() == dwarf::DW_TAG_string_type, "invalid tag", &N); |
1165 |
CheckDI(N.getTag() == dwarf::DW_TAG_string_type, "invalid tag", &N); |
| 1166 |
CheckDI(!(N.isBigEndian() && N.isLittleEndian()), "has conflicting flags", |
1166 |
CheckDI(!(N.isBigEndian() && N.isLittleEndian()), "has conflicting flags", |
| 1167 |
&N); |
1167 |
&N); |
| 1168 |
} |
1168 |
} |
| 1169 |
|
1169 |
|
| 1170 |
void Verifier::visitDIDerivedType(const DIDerivedType &N) { |
1170 |
void Verifier::visitDIDerivedType(const DIDerivedType &N) { |
| 1171 |
// Common scope checks. |
1171 |
// Common scope checks. |
| 1172 |
visitDIScope(N); |
1172 |
visitDIScope(N); |
| 1173 |
|
1173 |
|
| 1174 |
CheckDI(N.getTag() == dwarf::DW_TAG_typedef || |
1174 |
CheckDI(N.getTag() == dwarf::DW_TAG_typedef || |
| 1175 |
N.getTag() == dwarf::DW_TAG_pointer_type || |
1175 |
N.getTag() == dwarf::DW_TAG_pointer_type || |
| 1176 |
N.getTag() == dwarf::DW_TAG_ptr_to_member_type || |
1176 |
N.getTag() == dwarf::DW_TAG_ptr_to_member_type || |
| 1177 |
N.getTag() == dwarf::DW_TAG_reference_type || |
1177 |
N.getTag() == dwarf::DW_TAG_reference_type || |
| 1178 |
N.getTag() == dwarf::DW_TAG_rvalue_reference_type || |
1178 |
N.getTag() == dwarf::DW_TAG_rvalue_reference_type || |
| 1179 |
N.getTag() == dwarf::DW_TAG_const_type || |
1179 |
N.getTag() == dwarf::DW_TAG_const_type || |
| 1180 |
N.getTag() == dwarf::DW_TAG_immutable_type || |
1180 |
N.getTag() == dwarf::DW_TAG_immutable_type || |
| 1181 |
N.getTag() == dwarf::DW_TAG_volatile_type || |
1181 |
N.getTag() == dwarf::DW_TAG_volatile_type || |
| 1182 |
N.getTag() == dwarf::DW_TAG_restrict_type || |
1182 |
N.getTag() == dwarf::DW_TAG_restrict_type || |
| 1183 |
N.getTag() == dwarf::DW_TAG_atomic_type || |
1183 |
N.getTag() == dwarf::DW_TAG_atomic_type || |
| 1184 |
N.getTag() == dwarf::DW_TAG_member || |
1184 |
N.getTag() == dwarf::DW_TAG_member || |
| 1185 |
N.getTag() == dwarf::DW_TAG_inheritance || |
1185 |
N.getTag() == dwarf::DW_TAG_inheritance || |
| 1186 |
N.getTag() == dwarf::DW_TAG_friend || |
1186 |
N.getTag() == dwarf::DW_TAG_friend || |
| 1187 |
N.getTag() == dwarf::DW_TAG_set_type, |
1187 |
N.getTag() == dwarf::DW_TAG_set_type, |
| 1188 |
"invalid tag", &N); |
1188 |
"invalid tag", &N); |
| 1189 |
if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) { |
1189 |
if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) { |
| 1190 |
CheckDI(isType(N.getRawExtraData()), "invalid pointer to member type", &N, |
1190 |
CheckDI(isType(N.getRawExtraData()), "invalid pointer to member type", &N, |
| 1191 |
N.getRawExtraData()); |
1191 |
N.getRawExtraData()); |
| 1192 |
} |
1192 |
} |
| 1193 |
|
1193 |
|
| 1194 |
if (N.getTag() == dwarf::DW_TAG_set_type) { |
1194 |
if (N.getTag() == dwarf::DW_TAG_set_type) { |
| 1195 |
if (auto *T = N.getRawBaseType()) { |
1195 |
if (auto *T = N.getRawBaseType()) { |
| 1196 |
auto *Enum = dyn_cast_or_null(T); |
1196 |
auto *Enum = dyn_cast_or_null(T); |
| 1197 |
auto *Basic = dyn_cast_or_null(T); |
1197 |
auto *Basic = dyn_cast_or_null(T); |
| 1198 |
CheckDI( |
1198 |
CheckDI( |
| 1199 |
(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type) || |
1199 |
(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type) || |
| 1200 |
(Basic && (Basic->getEncoding() == dwarf::DW_ATE_unsigned || |
1200 |
(Basic && (Basic->getEncoding() == dwarf::DW_ATE_unsigned || |
| 1201 |
Basic->getEncoding() == dwarf::DW_ATE_signed || |
1201 |
Basic->getEncoding() == dwarf::DW_ATE_signed || |
| 1202 |
Basic->getEncoding() == dwarf::DW_ATE_unsigned_char || |
1202 |
Basic->getEncoding() == dwarf::DW_ATE_unsigned_char || |
| 1203 |
Basic->getEncoding() == dwarf::DW_ATE_signed_char || |
1203 |
Basic->getEncoding() == dwarf::DW_ATE_signed_char || |
| 1204 |
Basic->getEncoding() == dwarf::DW_ATE_boolean)), |
1204 |
Basic->getEncoding() == dwarf::DW_ATE_boolean)), |
| 1205 |
"invalid set base type", &N, T); |
1205 |
"invalid set base type", &N, T); |
| 1206 |
} |
1206 |
} |
| 1207 |
} |
1207 |
} |
| 1208 |
|
1208 |
|
| 1209 |
CheckDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope()); |
1209 |
CheckDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope()); |
| 1210 |
CheckDI(isType(N.getRawBaseType()), "invalid base type", &N, |
1210 |
CheckDI(isType(N.getRawBaseType()), "invalid base type", &N, |
| 1211 |
N.getRawBaseType()); |
1211 |
N.getRawBaseType()); |
| 1212 |
|
1212 |
|
| 1213 |
if (N.getDWARFAddressSpace()) { |
1213 |
if (N.getDWARFAddressSpace()) { |
| 1214 |
CheckDI(N.getTag() == dwarf::DW_TAG_pointer_type || |
1214 |
CheckDI(N.getTag() == dwarf::DW_TAG_pointer_type || |
| 1215 |
N.getTag() == dwarf::DW_TAG_reference_type || |
1215 |
N.getTag() == dwarf::DW_TAG_reference_type || |
| 1216 |
N.getTag() == dwarf::DW_TAG_rvalue_reference_type, |
1216 |
N.getTag() == dwarf::DW_TAG_rvalue_reference_type, |
| 1217 |
"DWARF address space only applies to pointer or reference types", |
1217 |
"DWARF address space only applies to pointer or reference types", |
| 1218 |
&N); |
1218 |
&N); |
| 1219 |
} |
1219 |
} |
| 1220 |
} |
1220 |
} |
| 1221 |
|
1221 |
|
| 1222 |
/// Detect mutually exclusive flags. |
1222 |
/// Detect mutually exclusive flags. |
| 1223 |
static bool hasConflictingReferenceFlags(unsigned Flags) { |
1223 |
static bool hasConflictingReferenceFlags(unsigned Flags) { |
| 1224 |
return ((Flags & DINode::FlagLValueReference) && |
1224 |
return ((Flags & DINode::FlagLValueReference) && |
| 1225 |
(Flags & DINode::FlagRValueReference)) || |
1225 |
(Flags & DINode::FlagRValueReference)) || |
| 1226 |
((Flags & DINode::FlagTypePassByValue) && |
1226 |
((Flags & DINode::FlagTypePassByValue) && |
| 1227 |
(Flags & DINode::FlagTypePassByReference)); |
1227 |
(Flags & DINode::FlagTypePassByReference)); |
| 1228 |
} |
1228 |
} |
| 1229 |
|
1229 |
|
| 1230 |
void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) { |
1230 |
void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) { |
| 1231 |
auto *Params = dyn_cast(&RawParams); |
1231 |
auto *Params = dyn_cast(&RawParams); |
| 1232 |
CheckDI(Params, "invalid template params", &N, &RawParams); |
1232 |
CheckDI(Params, "invalid template params", &N, &RawParams); |
| 1233 |
for (Metadata *Op : Params->operands()) { |
1233 |
for (Metadata *Op : Params->operands()) { |
| 1234 |
CheckDI(Op && isa(Op), "invalid template parameter", |
1234 |
CheckDI(Op && isa(Op), "invalid template parameter", |
| 1235 |
&N, Params, Op); |
1235 |
&N, Params, Op); |
| 1236 |
} |
1236 |
} |
| 1237 |
} |
1237 |
} |
| 1238 |
|
1238 |
|
| 1239 |
void Verifier::visitDICompositeType(const DICompositeType &N) { |
1239 |
void Verifier::visitDICompositeType(const DICompositeType &N) { |
| 1240 |
// Common scope checks. |
1240 |
// Common scope checks. |
| 1241 |
visitDIScope(N); |
1241 |
visitDIScope(N); |
| 1242 |
|
1242 |
|
| 1243 |
CheckDI(N.getTag() == dwarf::DW_TAG_array_type || |
1243 |
CheckDI(N.getTag() == dwarf::DW_TAG_array_type || |
| 1244 |
N.getTag() == dwarf::DW_TAG_structure_type || |
1244 |
N.getTag() == dwarf::DW_TAG_structure_type || |
| 1245 |
N.getTag() == dwarf::DW_TAG_union_type || |
1245 |
N.getTag() == dwarf::DW_TAG_union_type || |
| 1246 |
N.getTag() == dwarf::DW_TAG_enumeration_type || |
1246 |
N.getTag() == dwarf::DW_TAG_enumeration_type || |
| 1247 |
N.getTag() == dwarf::DW_TAG_class_type || |
1247 |
N.getTag() == dwarf::DW_TAG_class_type || |
| 1248 |
N.getTag() == dwarf::DW_TAG_variant_part || |
1248 |
N.getTag() == dwarf::DW_TAG_variant_part || |
| 1249 |
N.getTag() == dwarf::DW_TAG_namelist, |
1249 |
N.getTag() == dwarf::DW_TAG_namelist, |
| 1250 |
"invalid tag", &N); |
1250 |
"invalid tag", &N); |
| 1251 |
|
1251 |
|
| 1252 |
CheckDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope()); |
1252 |
CheckDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope()); |
| 1253 |
CheckDI(isType(N.getRawBaseType()), "invalid base type", &N, |
1253 |
CheckDI(isType(N.getRawBaseType()), "invalid base type", &N, |
| 1254 |
N.getRawBaseType()); |
1254 |
N.getRawBaseType()); |
| 1255 |
|
1255 |
|
| 1256 |
CheckDI(!N.getRawElements() || isa(N.getRawElements()), |
1256 |
CheckDI(!N.getRawElements() || isa(N.getRawElements()), |
| 1257 |
"invalid composite elements", &N, N.getRawElements()); |
1257 |
"invalid composite elements", &N, N.getRawElements()); |
| 1258 |
CheckDI(isType(N.getRawVTableHolder()), "invalid vtable holder", &N, |
1258 |
CheckDI(isType(N.getRawVTableHolder()), "invalid vtable holder", &N, |
| 1259 |
N.getRawVTableHolder()); |
1259 |
N.getRawVTableHolder()); |
| 1260 |
CheckDI(!hasConflictingReferenceFlags(N.getFlags()), |
1260 |
CheckDI(!hasConflictingReferenceFlags(N.getFlags()), |
| 1261 |
"invalid reference flags", &N); |
1261 |
"invalid reference flags", &N); |
| 1262 |
unsigned DIBlockByRefStruct = 1 << 4; |
1262 |
unsigned DIBlockByRefStruct = 1 << 4; |
| 1263 |
CheckDI((N.getFlags() & DIBlockByRefStruct) == 0, |
1263 |
CheckDI((N.getFlags() & DIBlockByRefStruct) == 0, |
| 1264 |
"DIBlockByRefStruct on DICompositeType is no longer supported", &N); |
1264 |
"DIBlockByRefStruct on DICompositeType is no longer supported", &N); |
| 1265 |
|
1265 |
|
| 1266 |
if (N.isVector()) { |
1266 |
if (N.isVector()) { |
| 1267 |
const DINodeArray Elements = N.getElements(); |
1267 |
const DINodeArray Elements = N.getElements(); |
| 1268 |
CheckDI(Elements.size() == 1 && |
1268 |
CheckDI(Elements.size() == 1 && |
| 1269 |
Elements[0]->getTag() == dwarf::DW_TAG_subrange_type, |
1269 |
Elements[0]->getTag() == dwarf::DW_TAG_subrange_type, |
| 1270 |
"invalid vector, expected one element of type subrange", &N); |
1270 |
"invalid vector, expected one element of type subrange", &N); |
| 1271 |
} |
1271 |
} |
| 1272 |
|
1272 |
|
| 1273 |
if (auto *Params = N.getRawTemplateParams()) |
1273 |
if (auto *Params = N.getRawTemplateParams()) |
| 1274 |
visitTemplateParams(N, *Params); |
1274 |
visitTemplateParams(N, *Params); |
| 1275 |
|
1275 |
|
| 1276 |
if (auto *D = N.getRawDiscriminator()) { |
1276 |
if (auto *D = N.getRawDiscriminator()) { |
| 1277 |
CheckDI(isa(D) && N.getTag() == dwarf::DW_TAG_variant_part, |
1277 |
CheckDI(isa(D) && N.getTag() == dwarf::DW_TAG_variant_part, |
| 1278 |
"discriminator can only appear on variant part"); |
1278 |
"discriminator can only appear on variant part"); |
| 1279 |
} |
1279 |
} |
| 1280 |
|
1280 |
|
| 1281 |
if (N.getRawDataLocation()) { |
1281 |
if (N.getRawDataLocation()) { |
| 1282 |
CheckDI(N.getTag() == dwarf::DW_TAG_array_type, |
1282 |
CheckDI(N.getTag() == dwarf::DW_TAG_array_type, |
| 1283 |
"dataLocation can only appear in array type"); |
1283 |
"dataLocation can only appear in array type"); |
| 1284 |
} |
1284 |
} |
| 1285 |
|
1285 |
|
| 1286 |
if (N.getRawAssociated()) { |
1286 |
if (N.getRawAssociated()) { |
| 1287 |
CheckDI(N.getTag() == dwarf::DW_TAG_array_type, |
1287 |
CheckDI(N.getTag() == dwarf::DW_TAG_array_type, |
| 1288 |
"associated can only appear in array type"); |
1288 |
"associated can only appear in array type"); |
| 1289 |
} |
1289 |
} |
| 1290 |
|
1290 |
|
| 1291 |
if (N.getRawAllocated()) { |
1291 |
if (N.getRawAllocated()) { |
| 1292 |
CheckDI(N.getTag() == dwarf::DW_TAG_array_type, |
1292 |
CheckDI(N.getTag() == dwarf::DW_TAG_array_type, |
| 1293 |
"allocated can only appear in array type"); |
1293 |
"allocated can only appear in array type"); |
| 1294 |
} |
1294 |
} |
| 1295 |
|
1295 |
|
| 1296 |
if (N.getRawRank()) { |
1296 |
if (N.getRawRank()) { |
| 1297 |
CheckDI(N.getTag() == dwarf::DW_TAG_array_type, |
1297 |
CheckDI(N.getTag() == dwarf::DW_TAG_array_type, |
| 1298 |
"rank can only appear in array type"); |
1298 |
"rank can only appear in array type"); |
| 1299 |
} |
1299 |
} |
| 1300 |
} |
1300 |
} |
| 1301 |
|
1301 |
|
| 1302 |
void Verifier::visitDISubroutineType(const DISubroutineType &N) { |
1302 |
void Verifier::visitDISubroutineType(const DISubroutineType &N) { |
| 1303 |
CheckDI(N.getTag() == dwarf::DW_TAG_subroutine_type, "invalid tag", &N); |
1303 |
CheckDI(N.getTag() == dwarf::DW_TAG_subroutine_type, "invalid tag", &N); |
| 1304 |
if (auto *Types = N.getRawTypeArray()) { |
1304 |
if (auto *Types = N.getRawTypeArray()) { |
| 1305 |
CheckDI(isa(Types), "invalid composite elements", &N, Types); |
1305 |
CheckDI(isa(Types), "invalid composite elements", &N, Types); |
| 1306 |
for (Metadata *Ty : N.getTypeArray()->operands()) { |
1306 |
for (Metadata *Ty : N.getTypeArray()->operands()) { |
| 1307 |
CheckDI(isType(Ty), "invalid subroutine type ref", &N, Types, Ty); |
1307 |
CheckDI(isType(Ty), "invalid subroutine type ref", &N, Types, Ty); |
| 1308 |
} |
1308 |
} |
| 1309 |
} |
1309 |
} |
| 1310 |
CheckDI(!hasConflictingReferenceFlags(N.getFlags()), |
1310 |
CheckDI(!hasConflictingReferenceFlags(N.getFlags()), |
| 1311 |
"invalid reference flags", &N); |
1311 |
"invalid reference flags", &N); |
| 1312 |
} |
1312 |
} |
| 1313 |
|
1313 |
|
| 1314 |
void Verifier::visitDIFile(const DIFile &N) { |
1314 |
void Verifier::visitDIFile(const DIFile &N) { |
| 1315 |
CheckDI(N.getTag() == dwarf::DW_TAG_file_type, "invalid tag", &N); |
1315 |
CheckDI(N.getTag() == dwarf::DW_TAG_file_type, "invalid tag", &N); |
| 1316 |
std::optional> Checksum = N.getChecksum(); |
1316 |
std::optional> Checksum = N.getChecksum(); |
| 1317 |
if (Checksum) { |
1317 |
if (Checksum) { |
| 1318 |
CheckDI(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last, |
1318 |
CheckDI(Checksum->Kind <= DIFile::ChecksumKind::CSK_Last, |
| 1319 |
"invalid checksum kind", &N); |
1319 |
"invalid checksum kind", &N); |
| 1320 |
size_t Size; |
1320 |
size_t Size; |
| 1321 |
switch (Checksum->Kind) { |
1321 |
switch (Checksum->Kind) { |
| 1322 |
case DIFile::CSK_MD5: |
1322 |
case DIFile::CSK_MD5: |
| 1323 |
Size = 32; |
1323 |
Size = 32; |
| 1324 |
break; |
1324 |
break; |
| 1325 |
case DIFile::CSK_SHA1: |
1325 |
case DIFile::CSK_SHA1: |
| 1326 |
Size = 40; |
1326 |
Size = 40; |
| 1327 |
break; |
1327 |
break; |
| 1328 |
case DIFile::CSK_SHA256: |
1328 |
case DIFile::CSK_SHA256: |
| 1329 |
Size = 64; |
1329 |
Size = 64; |
| 1330 |
break; |
1330 |
break; |
| 1331 |
} |
1331 |
} |
| 1332 |
CheckDI(Checksum->Value.size() == Size, "invalid checksum length", &N); |
1332 |
CheckDI(Checksum->Value.size() == Size, "invalid checksum length", &N); |
| 1333 |
CheckDI(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos, |
1333 |
CheckDI(Checksum->Value.find_if_not(llvm::isHexDigit) == StringRef::npos, |
| 1334 |
"invalid checksum", &N); |
1334 |
"invalid checksum", &N); |
| 1335 |
} |
1335 |
} |
| 1336 |
} |
1336 |
} |
| 1337 |
|
1337 |
|
| 1338 |
void Verifier::visitDICompileUnit(const DICompileUnit &N) { |
1338 |
void Verifier::visitDICompileUnit(const DICompileUnit &N) { |
| 1339 |
CheckDI(N.isDistinct(), "compile units must be distinct", &N); |
1339 |
CheckDI(N.isDistinct(), "compile units must be distinct", &N); |
| 1340 |
CheckDI(N.getTag() == dwarf::DW_TAG_compile_unit, "invalid tag", &N); |
1340 |
CheckDI(N.getTag() == dwarf::DW_TAG_compile_unit, "invalid tag", &N); |
| 1341 |
|
1341 |
|
| 1342 |
// Don't bother verifying the compilation directory or producer string |
1342 |
// Don't bother verifying the compilation directory or producer string |
| 1343 |
// as those could be empty. |
1343 |
// as those could be empty. |
| 1344 |
CheckDI(N.getRawFile() && isa(N.getRawFile()), "invalid file", &N, |
1344 |
CheckDI(N.getRawFile() && isa(N.getRawFile()), "invalid file", &N, |
| 1345 |
N.getRawFile()); |
1345 |
N.getRawFile()); |
| 1346 |
CheckDI(!N.getFile()->getFilename().empty(), "invalid filename", &N, |
1346 |
CheckDI(!N.getFile()->getFilename().empty(), "invalid filename", &N, |
| 1347 |
N.getFile()); |
1347 |
N.getFile()); |
| 1348 |
|
1348 |
|
| 1349 |
CurrentSourceLang = (dwarf::SourceLanguage)N.getSourceLanguage(); |
1349 |
CurrentSourceLang = (dwarf::SourceLanguage)N.getSourceLanguage(); |
| 1350 |
|
1350 |
|
| 1351 |
verifySourceDebugInfo(N, *N.getFile()); |
1351 |
verifySourceDebugInfo(N, *N.getFile()); |
| 1352 |
|
1352 |
|
| 1353 |
CheckDI((N.getEmissionKind() <= DICompileUnit::LastEmissionKind), |
1353 |
CheckDI((N.getEmissionKind() <= DICompileUnit::LastEmissionKind), |
| 1354 |
"invalid emission kind", &N); |
1354 |
"invalid emission kind", &N); |
| 1355 |
|
1355 |
|
| 1356 |
if (auto *Array = N.getRawEnumTypes()) { |
1356 |
if (auto *Array = N.getRawEnumTypes()) { |
| 1357 |
CheckDI(isa(Array), "invalid enum list", &N, Array); |
1357 |
CheckDI(isa(Array), "invalid enum list", &N, Array); |
| 1358 |
for (Metadata *Op : N.getEnumTypes()->operands()) { |
1358 |
for (Metadata *Op : N.getEnumTypes()->operands()) { |
| 1359 |
auto *Enum = dyn_cast_or_null(Op); |
1359 |
auto *Enum = dyn_cast_or_null(Op); |
| 1360 |
CheckDI(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type, |
1360 |
CheckDI(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type, |
| 1361 |
"invalid enum type", &N, N.getEnumTypes(), Op); |
1361 |
"invalid enum type", &N, N.getEnumTypes(), Op); |
| 1362 |
} |
1362 |
} |
| 1363 |
} |
1363 |
} |
| 1364 |
if (auto *Array = N.getRawRetainedTypes()) { |
1364 |
if (auto *Array = N.getRawRetainedTypes()) { |
| 1365 |
CheckDI(isa(Array), "invalid retained type list", &N, Array); |
1365 |
CheckDI(isa(Array), "invalid retained type list", &N, Array); |
| 1366 |
for (Metadata *Op : N.getRetainedTypes()->operands()) { |
1366 |
for (Metadata *Op : N.getRetainedTypes()->operands()) { |
| 1367 |
CheckDI( |
1367 |
CheckDI( |
| 1368 |
Op && (isa(Op) || (isa(Op) && |
1368 |
Op && (isa(Op) || (isa(Op) && |
| 1369 |
!cast(Op)->isDefinition())), |
1369 |
!cast(Op)->isDefinition())), |
| 1370 |
"invalid retained type", &N, Op); |
1370 |
"invalid retained type", &N, Op); |
| 1371 |
} |
1371 |
} |
| 1372 |
} |
1372 |
} |
| 1373 |
if (auto *Array = N.getRawGlobalVariables()) { |
1373 |
if (auto *Array = N.getRawGlobalVariables()) { |
| 1374 |
CheckDI(isa(Array), "invalid global variable list", &N, Array); |
1374 |
CheckDI(isa(Array), "invalid global variable list", &N, Array); |
| 1375 |
for (Metadata *Op : N.getGlobalVariables()->operands()) { |
1375 |
for (Metadata *Op : N.getGlobalVariables()->operands()) { |
| 1376 |
CheckDI(Op && (isa(Op)), |
1376 |
CheckDI(Op && (isa(Op)), |
| 1377 |
"invalid global variable ref", &N, Op); |
1377 |
"invalid global variable ref", &N, Op); |
| 1378 |
} |
1378 |
} |
| 1379 |
} |
1379 |
} |
| 1380 |
if (auto *Array = N.getRawImportedEntities()) { |
1380 |
if (auto *Array = N.getRawImportedEntities()) { |
| 1381 |
CheckDI(isa(Array), "invalid imported entity list", &N, Array); |
1381 |
CheckDI(isa(Array), "invalid imported entity list", &N, Array); |
| 1382 |
for (Metadata *Op : N.getImportedEntities()->operands()) { |
1382 |
for (Metadata *Op : N.getImportedEntities()->operands()) { |
| 1383 |
CheckDI(Op && isa(Op), "invalid imported entity ref", |
1383 |
CheckDI(Op && isa(Op), "invalid imported entity ref", |
| 1384 |
&N, Op); |
1384 |
&N, Op); |
| 1385 |
} |
1385 |
} |
| 1386 |
} |
1386 |
} |
| 1387 |
if (auto *Array = N.getRawMacros()) { |
1387 |
if (auto *Array = N.getRawMacros()) { |
| 1388 |
CheckDI(isa(Array), "invalid macro list", &N, Array); |
1388 |
CheckDI(isa(Array), "invalid macro list", &N, Array); |
| 1389 |
for (Metadata *Op : N.getMacros()->operands()) { |
1389 |
for (Metadata *Op : N.getMacros()->operands()) { |
| 1390 |
CheckDI(Op && isa(Op), "invalid macro ref", &N, Op); |
1390 |
CheckDI(Op && isa(Op), "invalid macro ref", &N, Op); |
| 1391 |
} |
1391 |
} |
| 1392 |
} |
1392 |
} |
| 1393 |
CUVisited.insert(&N); |
1393 |
CUVisited.insert(&N); |
| 1394 |
} |
1394 |
} |
| 1395 |
|
1395 |
|
| 1396 |
void Verifier::visitDISubprogram(const DISubprogram &N) { |
1396 |
void Verifier::visitDISubprogram(const DISubprogram &N) { |
| 1397 |
CheckDI(N.getTag() == dwarf::DW_TAG_subprogram, "invalid tag", &N); |
1397 |
CheckDI(N.getTag() == dwarf::DW_TAG_subprogram, "invalid tag", &N); |
| 1398 |
CheckDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope()); |
1398 |
CheckDI(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope()); |
| 1399 |
if (auto *F = N.getRawFile()) |
1399 |
if (auto *F = N.getRawFile()) |
| 1400 |
CheckDI(isa(F), "invalid file", &N, F); |
1400 |
CheckDI(isa(F), "invalid file", &N, F); |
| 1401 |
else |
1401 |
else |
| 1402 |
CheckDI(N.getLine() == 0, "line specified with no file", &N, N.getLine()); |
1402 |
CheckDI(N.getLine() == 0, "line specified with no file", &N, N.getLine()); |
| 1403 |
if (auto *T = N.getRawType()) |
1403 |
if (auto *T = N.getRawType()) |
| 1404 |
CheckDI(isa(T), "invalid subroutine type", &N, T); |
1404 |
CheckDI(isa(T), "invalid subroutine type", &N, T); |
| 1405 |
CheckDI(isType(N.getRawContainingType()), "invalid containing type", &N, |
1405 |
CheckDI(isType(N.getRawContainingType()), "invalid containing type", &N, |
| 1406 |
N.getRawContainingType()); |
1406 |
N.getRawContainingType()); |
| 1407 |
if (auto *Params = N.getRawTemplateParams()) |
1407 |
if (auto *Params = N.getRawTemplateParams()) |
| 1408 |
visitTemplateParams(N, *Params); |
1408 |
visitTemplateParams(N, *Params); |
| 1409 |
if (auto *S = N.getRawDeclaration()) |
1409 |
if (auto *S = N.getRawDeclaration()) |
| 1410 |
CheckDI(isa(S) && !cast(S)->isDefinition(), |
1410 |
CheckDI(isa(S) && !cast(S)->isDefinition(), |
| 1411 |
"invalid subprogram declaration", &N, S); |
1411 |
"invalid subprogram declaration", &N, S); |
| 1412 |
if (auto *RawNode = N.getRawRetainedNodes()) { |
1412 |
if (auto *RawNode = N.getRawRetainedNodes()) { |
| 1413 |
auto *Node = dyn_cast(RawNode); |
1413 |
auto *Node = dyn_cast(RawNode); |
| 1414 |
CheckDI(Node, "invalid retained nodes list", &N, RawNode); |
1414 |
CheckDI(Node, "invalid retained nodes list", &N, RawNode); |
| 1415 |
for (Metadata *Op : Node->operands()) { |
1415 |
for (Metadata *Op : Node->operands()) { |
| 1416 |
CheckDI(Op && (isa(Op) || isa(Op) || |
1416 |
CheckDI(Op && (isa(Op) || isa(Op) || |
| 1417 |
isa(Op)), |
1417 |
isa(Op)), |
| 1418 |
"invalid retained nodes, expected DILocalVariable, DILabel or " |
1418 |
"invalid retained nodes, expected DILocalVariable, DILabel or " |
| 1419 |
"DIImportedEntity", |
1419 |
"DIImportedEntity", |
| 1420 |
&N, Node, Op); |
1420 |
&N, Node, Op); |
| 1421 |
} |
1421 |
} |
| 1422 |
} |
1422 |
} |
| 1423 |
CheckDI(!hasConflictingReferenceFlags(N.getFlags()), |
1423 |
CheckDI(!hasConflictingReferenceFlags(N.getFlags()), |
| 1424 |
"invalid reference flags", &N); |
1424 |
"invalid reference flags", &N); |
| 1425 |
|
1425 |
|
| 1426 |
auto *Unit = N.getRawUnit(); |
1426 |
auto *Unit = N.getRawUnit(); |
| 1427 |
if (N.isDefinition()) { |
1427 |
if (N.isDefinition()) { |
| 1428 |
// Subprogram definitions (not part of the type hierarchy). |
1428 |
// Subprogram definitions (not part of the type hierarchy). |
| 1429 |
CheckDI(N.isDistinct(), "subprogram definitions must be distinct", &N); |
1429 |
CheckDI(N.isDistinct(), "subprogram definitions must be distinct", &N); |
| 1430 |
CheckDI(Unit, "subprogram definitions must have a compile unit", &N); |
1430 |
CheckDI(Unit, "subprogram definitions must have a compile unit", &N); |
| 1431 |
CheckDI(isa(Unit), "invalid unit type", &N, Unit); |
1431 |
CheckDI(isa(Unit), "invalid unit type", &N, Unit); |
| 1432 |
// There's no good way to cross the CU boundary to insert a nested |
1432 |
// There's no good way to cross the CU boundary to insert a nested |
| 1433 |
// DISubprogram definition in one CU into a type defined in another CU. |
1433 |
// DISubprogram definition in one CU into a type defined in another CU. |
| 1434 |
auto *CT = dyn_cast_or_null(N.getRawScope()); |
1434 |
auto *CT = dyn_cast_or_null(N.getRawScope()); |
| 1435 |
if (CT && CT->getRawIdentifier() && |
1435 |
if (CT && CT->getRawIdentifier() && |
| 1436 |
M.getContext().isODRUniquingDebugTypes()) |
1436 |
M.getContext().isODRUniquingDebugTypes()) |
| 1437 |
CheckDI(N.getDeclaration(), |
1437 |
CheckDI(N.getDeclaration(), |
| 1438 |
"definition subprograms cannot be nested within DICompositeType " |
1438 |
"definition subprograms cannot be nested within DICompositeType " |
| 1439 |
"when enabling ODR", |
1439 |
"when enabling ODR", |
| 1440 |
&N); |
1440 |
&N); |
| 1441 |
if (N.getFile()) |
1441 |
if (N.getFile()) |
| 1442 |
verifySourceDebugInfo(*N.getUnit(), *N.getFile()); |
1442 |
verifySourceDebugInfo(*N.getUnit(), *N.getFile()); |
| 1443 |
} else { |
1443 |
} else { |
| 1444 |
// Subprogram declarations (part of the type hierarchy). |
1444 |
// Subprogram declarations (part of the type hierarchy). |
| 1445 |
CheckDI(!Unit, "subprogram declarations must not have a compile unit", &N); |
1445 |
CheckDI(!Unit, "subprogram declarations must not have a compile unit", &N); |
| 1446 |
CheckDI(!N.getRawDeclaration(), |
1446 |
CheckDI(!N.getRawDeclaration(), |
| 1447 |
"subprogram declaration must not have a declaration field"); |
1447 |
"subprogram declaration must not have a declaration field"); |
| 1448 |
} |
1448 |
} |
| 1449 |
|
1449 |
|
| 1450 |
if (auto *RawThrownTypes = N.getRawThrownTypes()) { |
1450 |
if (auto *RawThrownTypes = N.getRawThrownTypes()) { |
| 1451 |
auto *ThrownTypes = dyn_cast(RawThrownTypes); |
1451 |
auto *ThrownTypes = dyn_cast(RawThrownTypes); |
| 1452 |
CheckDI(ThrownTypes, "invalid thrown types list", &N, RawThrownTypes); |
1452 |
CheckDI(ThrownTypes, "invalid thrown types list", &N, RawThrownTypes); |
| 1453 |
for (Metadata *Op : ThrownTypes->operands()) |
1453 |
for (Metadata *Op : ThrownTypes->operands()) |
| 1454 |
CheckDI(Op && isa(Op), "invalid thrown type", &N, ThrownTypes, |
1454 |
CheckDI(Op && isa(Op), "invalid thrown type", &N, ThrownTypes, |
| 1455 |
Op); |
1455 |
Op); |
| 1456 |
} |
1456 |
} |
| 1457 |
|
1457 |
|
| 1458 |
if (N.areAllCallsDescribed()) |
1458 |
if (N.areAllCallsDescribed()) |
| 1459 |
CheckDI(N.isDefinition(), |
1459 |
CheckDI(N.isDefinition(), |
| 1460 |
"DIFlagAllCallsDescribed must be attached to a definition"); |
1460 |
"DIFlagAllCallsDescribed must be attached to a definition"); |
| 1461 |
} |
1461 |
} |
| 1462 |
|
1462 |
|
| 1463 |
void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) { |
1463 |
void Verifier::visitDILexicalBlockBase(const DILexicalBlockBase &N) { |
| 1464 |
CheckDI(N.getTag() == dwarf::DW_TAG_lexical_block, "invalid tag", &N); |
1464 |
CheckDI(N.getTag() == dwarf::DW_TAG_lexical_block, "invalid tag", &N); |
| 1465 |
CheckDI(N.getRawScope() && isa(N.getRawScope()), |
1465 |
CheckDI(N.getRawScope() && isa(N.getRawScope()), |
| 1466 |
"invalid local scope", &N, N.getRawScope()); |
1466 |
"invalid local scope", &N, N.getRawScope()); |
| 1467 |
if (auto *SP = dyn_cast(N.getRawScope())) |
1467 |
if (auto *SP = dyn_cast(N.getRawScope())) |
| 1468 |
CheckDI(SP->isDefinition(), "scope points into the type hierarchy", &N); |
1468 |
CheckDI(SP->isDefinition(), "scope points into the type hierarchy", &N); |
| 1469 |
} |
1469 |
} |
| 1470 |
|
1470 |
|
| 1471 |
void Verifier::visitDILexicalBlock(const DILexicalBlock &N) { |
1471 |
void Verifier::visitDILexicalBlock(const DILexicalBlock &N) { |
| 1472 |
visitDILexicalBlockBase(N); |
1472 |
visitDILexicalBlockBase(N); |
| 1473 |
|
1473 |
|
| 1474 |
CheckDI(N.getLine() || !N.getColumn(), |
1474 |
CheckDI(N.getLine() || !N.getColumn(), |
| 1475 |
"cannot have column info without line info", &N); |
1475 |
"cannot have column info without line info", &N); |
| 1476 |
} |
1476 |
} |
| 1477 |
|
1477 |
|
| 1478 |
void Verifier::visitDILexicalBlockFile(const DILexicalBlockFile &N) { |
1478 |
void Verifier::visitDILexicalBlockFile(const DILexicalBlockFile &N) { |
| 1479 |
visitDILexicalBlockBase(N); |
1479 |
visitDILexicalBlockBase(N); |
| 1480 |
} |
1480 |
} |
| 1481 |
|
1481 |
|
| 1482 |
void Verifier::visitDICommonBlock(const DICommonBlock &N) { |
1482 |
void Verifier::visitDICommonBlock(const DICommonBlock &N) { |
| 1483 |
CheckDI(N.getTag() == dwarf::DW_TAG_common_block, "invalid tag", &N); |
1483 |
CheckDI(N.getTag() == dwarf::DW_TAG_common_block, "invalid tag", &N); |
| 1484 |
if (auto *S = N.getRawScope()) |
1484 |
if (auto *S = N.getRawScope()) |
| 1485 |
CheckDI(isa(S), "invalid scope ref", &N, S); |
1485 |
CheckDI(isa(S), "invalid scope ref", &N, S); |
| 1486 |
if (auto *S = N.getRawDecl()) |
1486 |
if (auto *S = N.getRawDecl()) |
| 1487 |
CheckDI(isa(S), "invalid declaration", &N, S); |
1487 |
CheckDI(isa(S), "invalid declaration", &N, S); |
| 1488 |
} |
1488 |
} |
| 1489 |
|
1489 |
|
| 1490 |
void Verifier::visitDINamespace(const DINamespace &N) { |
1490 |
void Verifier::visitDINamespace(const DINamespace &N) { |
| 1491 |
CheckDI(N.getTag() == dwarf::DW_TAG_namespace, "invalid tag", &N); |
1491 |
CheckDI(N.getTag() == dwarf::DW_TAG_namespace, "invalid tag", &N); |
| 1492 |
if (auto *S = N.getRawScope()) |
1492 |
if (auto *S = N.getRawScope()) |
| 1493 |
CheckDI(isa(S), "invalid scope ref", &N, S); |
1493 |
CheckDI(isa(S), "invalid scope ref", &N, S); |
| 1494 |
} |
1494 |
} |
| 1495 |
|
1495 |
|
| 1496 |
void Verifier::visitDIMacro(const DIMacro &N) { |
1496 |
void Verifier::visitDIMacro(const DIMacro &N) { |
| 1497 |
CheckDI(N.getMacinfoType() == dwarf::DW_MACINFO_define || |
1497 |
CheckDI(N.getMacinfoType() == dwarf::DW_MACINFO_define || |
| 1498 |
N.getMacinfoType() == dwarf::DW_MACINFO_undef, |
1498 |
N.getMacinfoType() == dwarf::DW_MACINFO_undef, |
| 1499 |
"invalid macinfo type", &N); |
1499 |
"invalid macinfo type", &N); |
| 1500 |
CheckDI(!N.getName().empty(), "anonymous macro", &N); |
1500 |
CheckDI(!N.getName().empty(), "anonymous macro", &N); |
| 1501 |
if (!N.getValue().empty()) { |
1501 |
if (!N.getValue().empty()) { |
| 1502 |
assert(N.getValue().data()[0] != ' ' && "Macro value has a space prefix"); |
1502 |
assert(N.getValue().data()[0] != ' ' && "Macro value has a space prefix"); |
| 1503 |
} |
1503 |
} |
| 1504 |
} |
1504 |
} |
| 1505 |
|
1505 |
|
| 1506 |
void Verifier::visitDIMacroFile(const DIMacroFile &N) { |
1506 |
void Verifier::visitDIMacroFile(const DIMacroFile &N) { |
| 1507 |
CheckDI(N.getMacinfoType() == dwarf::DW_MACINFO_start_file, |
1507 |
CheckDI(N.getMacinfoType() == dwarf::DW_MACINFO_start_file, |
| 1508 |
"invalid macinfo type", &N); |
1508 |
"invalid macinfo type", &N); |
| 1509 |
if (auto *F = N.getRawFile()) |
1509 |
if (auto *F = N.getRawFile()) |
| 1510 |
CheckDI(isa(F), "invalid file", &N, F); |
1510 |
CheckDI(isa(F), "invalid file", &N, F); |
| 1511 |
|
1511 |
|
| 1512 |
if (auto *Array = N.getRawElements()) { |
1512 |
if (auto *Array = N.getRawElements()) { |
| 1513 |
CheckDI(isa(Array), "invalid macro list", &N, Array); |
1513 |
CheckDI(isa(Array), "invalid macro list", &N, Array); |
| 1514 |
for (Metadata *Op : N.getElements()->operands()) { |
1514 |
for (Metadata *Op : N.getElements()->operands()) { |
| 1515 |
CheckDI(Op && isa(Op), "invalid macro ref", &N, Op); |
1515 |
CheckDI(Op && isa(Op), "invalid macro ref", &N, Op); |
| 1516 |
} |
1516 |
} |
| 1517 |
} |
1517 |
} |
| 1518 |
} |
1518 |
} |
| 1519 |
|
1519 |
|
| 1520 |
void Verifier::visitDIArgList(const DIArgList &N) { |
1520 |
void Verifier::visitDIArgList(const DIArgList &N) { |
| 1521 |
CheckDI(!N.getNumOperands(), |
1521 |
CheckDI(!N.getNumOperands(), |
| 1522 |
"DIArgList should have no operands other than a list of " |
1522 |
"DIArgList should have no operands other than a list of " |
| 1523 |
"ValueAsMetadata", |
1523 |
"ValueAsMetadata", |
| 1524 |
&N); |
1524 |
&N); |
| 1525 |
} |
1525 |
} |
| 1526 |
|
1526 |
|
| 1527 |
void Verifier::visitDIModule(const DIModule &N) { |
1527 |
void Verifier::visitDIModule(const DIModule &N) { |
| 1528 |
CheckDI(N.getTag() == dwarf::DW_TAG_module, "invalid tag", &N); |
1528 |
CheckDI(N.getTag() == dwarf::DW_TAG_module, "invalid tag", &N); |
| 1529 |
CheckDI(!N.getName().empty(), "anonymous module", &N); |
1529 |
CheckDI(!N.getName().empty(), "anonymous module", &N); |
| 1530 |
} |
1530 |
} |
| 1531 |
|
1531 |
|
| 1532 |
void Verifier::visitDITemplateParameter(const DITemplateParameter &N) { |
1532 |
void Verifier::visitDITemplateParameter(const DITemplateParameter &N) { |
| 1533 |
CheckDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType()); |
1533 |
CheckDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType()); |
| 1534 |
} |
1534 |
} |
| 1535 |
|
1535 |
|
| 1536 |
void Verifier::visitDITemplateTypeParameter(const DITemplateTypeParameter &N) { |
1536 |
void Verifier::visitDITemplateTypeParameter(const DITemplateTypeParameter &N) { |
| 1537 |
visitDITemplateParameter(N); |
1537 |
visitDITemplateParameter(N); |
| 1538 |
|
1538 |
|
| 1539 |
CheckDI(N.getTag() == dwarf::DW_TAG_template_type_parameter, "invalid tag", |
1539 |
CheckDI(N.getTag() == dwarf::DW_TAG_template_type_parameter, "invalid tag", |
| 1540 |
&N); |
1540 |
&N); |
| 1541 |
} |
1541 |
} |
| 1542 |
|
1542 |
|
| 1543 |
void Verifier::visitDITemplateValueParameter( |
1543 |
void Verifier::visitDITemplateValueParameter( |
| 1544 |
const DITemplateValueParameter &N) { |
1544 |
const DITemplateValueParameter &N) { |
| 1545 |
visitDITemplateParameter(N); |
1545 |
visitDITemplateParameter(N); |
| 1546 |
|
1546 |
|
| 1547 |
CheckDI(N.getTag() == dwarf::DW_TAG_template_value_parameter || |
1547 |
CheckDI(N.getTag() == dwarf::DW_TAG_template_value_parameter || |
| 1548 |
N.getTag() == dwarf::DW_TAG_GNU_template_template_param || |
1548 |
N.getTag() == dwarf::DW_TAG_GNU_template_template_param || |
| 1549 |
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack, |
1549 |
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack, |
| 1550 |
"invalid tag", &N); |
1550 |
"invalid tag", &N); |
| 1551 |
} |
1551 |
} |
| 1552 |
|
1552 |
|
| 1553 |
void Verifier::visitDIVariable(const DIVariable &N) { |
1553 |
void Verifier::visitDIVariable(const DIVariable &N) { |
| 1554 |
if (auto *S = N.getRawScope()) |
1554 |
if (auto *S = N.getRawScope()) |
| 1555 |
CheckDI(isa(S), "invalid scope", &N, S); |
1555 |
CheckDI(isa(S), "invalid scope", &N, S); |
| 1556 |
if (auto *F = N.getRawFile()) |
1556 |
if (auto *F = N.getRawFile()) |
| 1557 |
CheckDI(isa(F), "invalid file", &N, F); |
1557 |
CheckDI(isa(F), "invalid file", &N, F); |
| 1558 |
} |
1558 |
} |
| 1559 |
|
1559 |
|
| 1560 |
void Verifier::visitDIGlobalVariable(const DIGlobalVariable &N) { |
1560 |
void Verifier::visitDIGlobalVariable(const DIGlobalVariable &N) { |
| 1561 |
// Checks common to all variables. |
1561 |
// Checks common to all variables. |
| 1562 |
visitDIVariable(N); |
1562 |
visitDIVariable(N); |
| 1563 |
|
1563 |
|
| 1564 |
CheckDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N); |
1564 |
CheckDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N); |
| 1565 |
CheckDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType()); |
1565 |
CheckDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType()); |
| 1566 |
// Check only if the global variable is not an extern |
1566 |
// Check only if the global variable is not an extern |
| 1567 |
if (N.isDefinition()) |
1567 |
if (N.isDefinition()) |
| 1568 |
CheckDI(N.getType(), "missing global variable type", &N); |
1568 |
CheckDI(N.getType(), "missing global variable type", &N); |
| 1569 |
if (auto *Member = N.getRawStaticDataMemberDeclaration()) { |
1569 |
if (auto *Member = N.getRawStaticDataMemberDeclaration()) { |
| 1570 |
CheckDI(isa(Member), |
1570 |
CheckDI(isa(Member), |
| 1571 |
"invalid static data member declaration", &N, Member); |
1571 |
"invalid static data member declaration", &N, Member); |
| 1572 |
} |
1572 |
} |
| 1573 |
} |
1573 |
} |
| 1574 |
|
1574 |
|
| 1575 |
void Verifier::visitDILocalVariable(const DILocalVariable &N) { |
1575 |
void Verifier::visitDILocalVariable(const DILocalVariable &N) { |
| 1576 |
// Checks common to all variables. |
1576 |
// Checks common to all variables. |
| 1577 |
visitDIVariable(N); |
1577 |
visitDIVariable(N); |
| 1578 |
|
1578 |
|
| 1579 |
CheckDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType()); |
1579 |
CheckDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType()); |
| 1580 |
CheckDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N); |
1580 |
CheckDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N); |
| 1581 |
CheckDI(N.getRawScope() && isa(N.getRawScope()), |
1581 |
CheckDI(N.getRawScope() && isa(N.getRawScope()), |
| 1582 |
"local variable requires a valid scope", &N, N.getRawScope()); |
1582 |
"local variable requires a valid scope", &N, N.getRawScope()); |
| 1583 |
if (auto Ty = N.getType()) |
1583 |
if (auto Ty = N.getType()) |
| 1584 |
CheckDI(!isa(Ty), "invalid type", &N, N.getType()); |
1584 |
CheckDI(!isa(Ty), "invalid type", &N, N.getType()); |
| 1585 |
} |
1585 |
} |
| 1586 |
|
1586 |
|
| 1587 |
void Verifier::visitDIAssignID(const DIAssignID &N) { |
1587 |
void Verifier::visitDIAssignID(const DIAssignID &N) { |
| 1588 |
CheckDI(!N.getNumOperands(), "DIAssignID has no arguments", &N); |
1588 |
CheckDI(!N.getNumOperands(), "DIAssignID has no arguments", &N); |
| 1589 |
CheckDI(N.isDistinct(), "DIAssignID must be distinct", &N); |
1589 |
CheckDI(N.isDistinct(), "DIAssignID must be distinct", &N); |
| 1590 |
} |
1590 |
} |
| 1591 |
|
1591 |
|
| 1592 |
void Verifier::visitDILabel(const DILabel &N) { |
1592 |
void Verifier::visitDILabel(const DILabel &N) { |
| 1593 |
if (auto *S = N.getRawScope()) |
1593 |
if (auto *S = N.getRawScope()) |
| 1594 |
CheckDI(isa(S), "invalid scope", &N, S); |
1594 |
CheckDI(isa(S), "invalid scope", &N, S); |
| 1595 |
if (auto *F = N.getRawFile()) |
1595 |
if (auto *F = N.getRawFile()) |
| 1596 |
CheckDI(isa(F), "invalid file", &N, F); |
1596 |
CheckDI(isa(F), "invalid file", &N, F); |
| 1597 |
|
1597 |
|
| 1598 |
CheckDI(N.getTag() == dwarf::DW_TAG_label, "invalid tag", &N); |
1598 |
CheckDI(N.getTag() == dwarf::DW_TAG_label, "invalid tag", &N); |
| 1599 |
CheckDI(N.getRawScope() && isa(N.getRawScope()), |
1599 |
CheckDI(N.getRawScope() && isa(N.getRawScope()), |
| 1600 |
"label requires a valid scope", &N, N.getRawScope()); |
1600 |
"label requires a valid scope", &N, N.getRawScope()); |
| 1601 |
} |
1601 |
} |
| 1602 |
|
1602 |
|
| 1603 |
void Verifier::visitDIExpression(const DIExpression &N) { |
1603 |
void Verifier::visitDIExpression(const DIExpression &N) { |
| 1604 |
CheckDI(N.isValid(), "invalid expression", &N); |
1604 |
CheckDI(N.isValid(), "invalid expression", &N); |
| 1605 |
} |
1605 |
} |
| 1606 |
|
1606 |
|
| 1607 |
void Verifier::visitDIGlobalVariableExpression( |
1607 |
void Verifier::visitDIGlobalVariableExpression( |
| 1608 |
const DIGlobalVariableExpression &GVE) { |
1608 |
const DIGlobalVariableExpression &GVE) { |
| 1609 |
CheckDI(GVE.getVariable(), "missing variable"); |
1609 |
CheckDI(GVE.getVariable(), "missing variable"); |
| 1610 |
if (auto *Var = GVE.getVariable()) |
1610 |
if (auto *Var = GVE.getVariable()) |
| 1611 |
visitDIGlobalVariable(*Var); |
1611 |
visitDIGlobalVariable(*Var); |
| 1612 |
if (auto *Expr = GVE.getExpression()) { |
1612 |
if (auto *Expr = GVE.getExpression()) { |
| 1613 |
visitDIExpression(*Expr); |
1613 |
visitDIExpression(*Expr); |
| 1614 |
if (auto Fragment = Expr->getFragmentInfo()) |
1614 |
if (auto Fragment = Expr->getFragmentInfo()) |
| 1615 |
verifyFragmentExpression(*GVE.getVariable(), *Fragment, &GVE); |
1615 |
verifyFragmentExpression(*GVE.getVariable(), *Fragment, &GVE); |
| 1616 |
} |
1616 |
} |
| 1617 |
} |
1617 |
} |
| 1618 |
|
1618 |
|
| 1619 |
void Verifier::visitDIObjCProperty(const DIObjCProperty &N) { |
1619 |
void Verifier::visitDIObjCProperty(const DIObjCProperty &N) { |
| 1620 |
CheckDI(N.getTag() == dwarf::DW_TAG_APPLE_property, "invalid tag", &N); |
1620 |
CheckDI(N.getTag() == dwarf::DW_TAG_APPLE_property, "invalid tag", &N); |
| 1621 |
if (auto *T = N.getRawType()) |
1621 |
if (auto *T = N.getRawType()) |
| 1622 |
CheckDI(isType(T), "invalid type ref", &N, T); |
1622 |
CheckDI(isType(T), "invalid type ref", &N, T); |
| 1623 |
if (auto *F = N.getRawFile()) |
1623 |
if (auto *F = N.getRawFile()) |
| 1624 |
CheckDI(isa(F), "invalid file", &N, F); |
1624 |
CheckDI(isa(F), "invalid file", &N, F); |
| 1625 |
} |
1625 |
} |
| 1626 |
|
1626 |
|
| 1627 |
void Verifier::visitDIImportedEntity(const DIImportedEntity &N) { |
1627 |
void Verifier::visitDIImportedEntity(const DIImportedEntity &N) { |
| 1628 |
CheckDI(N.getTag() == dwarf::DW_TAG_imported_module || |
1628 |
CheckDI(N.getTag() == dwarf::DW_TAG_imported_module || |
| 1629 |
N.getTag() == dwarf::DW_TAG_imported_declaration, |
1629 |
N.getTag() == dwarf::DW_TAG_imported_declaration, |
| 1630 |
"invalid tag", &N); |
1630 |
"invalid tag", &N); |
| 1631 |
if (auto *S = N.getRawScope()) |
1631 |
if (auto *S = N.getRawScope()) |
| 1632 |
CheckDI(isa(S), "invalid scope for imported entity", &N, S); |
1632 |
CheckDI(isa(S), "invalid scope for imported entity", &N, S); |
| 1633 |
CheckDI(isDINode(N.getRawEntity()), "invalid imported entity", &N, |
1633 |
CheckDI(isDINode(N.getRawEntity()), "invalid imported entity", &N, |
| 1634 |
N.getRawEntity()); |
1634 |
N.getRawEntity()); |
| 1635 |
} |
1635 |
} |
| 1636 |
|
1636 |
|
| 1637 |
void Verifier::visitComdat(const Comdat &C) { |
1637 |
void Verifier::visitComdat(const Comdat &C) { |
| 1638 |
// In COFF the Module is invalid if the GlobalValue has private linkage. |
1638 |
// In COFF the Module is invalid if the GlobalValue has private linkage. |
| 1639 |
// Entities with private linkage don't have entries in the symbol table. |
1639 |
// Entities with private linkage don't have entries in the symbol table. |
| 1640 |
if (TT.isOSBinFormatCOFF()) |
1640 |
if (TT.isOSBinFormatCOFF()) |
| 1641 |
if (const GlobalValue *GV = M.getNamedValue(C.getName())) |
1641 |
if (const GlobalValue *GV = M.getNamedValue(C.getName())) |
| 1642 |
Check(!GV->hasPrivateLinkage(), "comdat global value has private linkage", |
1642 |
Check(!GV->hasPrivateLinkage(), "comdat global value has private linkage", |
| 1643 |
GV); |
1643 |
GV); |
| 1644 |
} |
1644 |
} |
| 1645 |
|
1645 |
|
| 1646 |
void Verifier::visitModuleIdents() { |
1646 |
void Verifier::visitModuleIdents() { |
| 1647 |
const NamedMDNode *Idents = M.getNamedMetadata("llvm.ident"); |
1647 |
const NamedMDNode *Idents = M.getNamedMetadata("llvm.ident"); |
| 1648 |
if (!Idents) |
1648 |
if (!Idents) |
| 1649 |
return; |
1649 |
return; |
| 1650 |
|
1650 |
|
| 1651 |
// llvm.ident takes a list of metadata entry. Each entry has only one string. |
1651 |
// llvm.ident takes a list of metadata entry. Each entry has only one string. |
| 1652 |
// Scan each llvm.ident entry and make sure that this requirement is met. |
1652 |
// Scan each llvm.ident entry and make sure that this requirement is met. |
| 1653 |
for (const MDNode *N : Idents->operands()) { |
1653 |
for (const MDNode *N : Idents->operands()) { |
| 1654 |
Check(N->getNumOperands() == 1, |
1654 |
Check(N->getNumOperands() == 1, |
| 1655 |
"incorrect number of operands in llvm.ident metadata", N); |
1655 |
"incorrect number of operands in llvm.ident metadata", N); |
| 1656 |
Check(dyn_cast_or_null(N->getOperand(0)), |
1656 |
Check(dyn_cast_or_null(N->getOperand(0)), |
| 1657 |
("invalid value for llvm.ident metadata entry operand" |
1657 |
("invalid value for llvm.ident metadata entry operand" |
| 1658 |
"(the operand should be a string)"), |
1658 |
"(the operand should be a string)"), |
| 1659 |
N->getOperand(0)); |
1659 |
N->getOperand(0)); |
| 1660 |
} |
1660 |
} |
| 1661 |
} |
1661 |
} |
| 1662 |
|
1662 |
|
| 1663 |
void Verifier::visitModuleCommandLines() { |
1663 |
void Verifier::visitModuleCommandLines() { |
| 1664 |
const NamedMDNode *CommandLines = M.getNamedMetadata("llvm.commandline"); |
1664 |
const NamedMDNode *CommandLines = M.getNamedMetadata("llvm.commandline"); |
| 1665 |
if (!CommandLines) |
1665 |
if (!CommandLines) |
| 1666 |
return; |
1666 |
return; |
| 1667 |
|
1667 |
|
| 1668 |
// llvm.commandline takes a list of metadata entry. Each entry has only one |
1668 |
// llvm.commandline takes a list of metadata entry. Each entry has only one |
| 1669 |
// string. Scan each llvm.commandline entry and make sure that this |
1669 |
// string. Scan each llvm.commandline entry and make sure that this |
| 1670 |
// requirement is met. |
1670 |
// requirement is met. |
| 1671 |
for (const MDNode *N : CommandLines->operands()) { |
1671 |
for (const MDNode *N : CommandLines->operands()) { |
| 1672 |
Check(N->getNumOperands() == 1, |
1672 |
Check(N->getNumOperands() == 1, |
| 1673 |
"incorrect number of operands in llvm.commandline metadata", N); |
1673 |
"incorrect number of operands in llvm.commandline metadata", N); |
| 1674 |
Check(dyn_cast_or_null(N->getOperand(0)), |
1674 |
Check(dyn_cast_or_null(N->getOperand(0)), |
| 1675 |
("invalid value for llvm.commandline metadata entry operand" |
1675 |
("invalid value for llvm.commandline metadata entry operand" |
| 1676 |
"(the operand should be a string)"), |
1676 |
"(the operand should be a string)"), |
| 1677 |
N->getOperand(0)); |
1677 |
N->getOperand(0)); |
| 1678 |
} |
1678 |
} |
| 1679 |
} |
1679 |
} |
| 1680 |
|
1680 |
|
| 1681 |
void Verifier::visitModuleFlags() { |
1681 |
void Verifier::visitModuleFlags() { |
| 1682 |
const NamedMDNode *Flags = M.getModuleFlagsMetadata(); |
1682 |
const NamedMDNode *Flags = M.getModuleFlagsMetadata(); |
| 1683 |
if (!Flags) return; |
1683 |
if (!Flags) return; |
| 1684 |
|
1684 |
|
| 1685 |
// Scan each flag, and track the flags and requirements. |
1685 |
// Scan each flag, and track the flags and requirements. |
| 1686 |
DenseMap SeenIDs; |
1686 |
DenseMap SeenIDs; |
| 1687 |
SmallVector Requirements; |
1687 |
SmallVector Requirements; |
| 1688 |
for (const MDNode *MDN : Flags->operands()) |
1688 |
for (const MDNode *MDN : Flags->operands()) |
| 1689 |
visitModuleFlag(MDN, SeenIDs, Requirements); |
1689 |
visitModuleFlag(MDN, SeenIDs, Requirements); |
| 1690 |
|
1690 |
|
| 1691 |
// Validate that the requirements in the module are valid. |
1691 |
// Validate that the requirements in the module are valid. |
| 1692 |
for (const MDNode *Requirement : Requirements) { |
1692 |
for (const MDNode *Requirement : Requirements) { |
| 1693 |
const MDString *Flag = cast(Requirement->getOperand(0)); |
1693 |
const MDString *Flag = cast(Requirement->getOperand(0)); |
| 1694 |
const Metadata *ReqValue = Requirement->getOperand(1); |
1694 |
const Metadata *ReqValue = Requirement->getOperand(1); |
| 1695 |
|
1695 |
|
| 1696 |
const MDNode *Op = SeenIDs.lookup(Flag); |
1696 |
const MDNode *Op = SeenIDs.lookup(Flag); |
| 1697 |
if (!Op) { |
1697 |
if (!Op) { |
| 1698 |
CheckFailed("invalid requirement on flag, flag is not present in module", |
1698 |
CheckFailed("invalid requirement on flag, flag is not present in module", |
| 1699 |
Flag); |
1699 |
Flag); |
| 1700 |
continue; |
1700 |
continue; |
| 1701 |
} |
1701 |
} |
| 1702 |
|
1702 |
|
| 1703 |
if (Op->getOperand(2) != ReqValue) { |
1703 |
if (Op->getOperand(2) != ReqValue) { |
| 1704 |
CheckFailed(("invalid requirement on flag, " |
1704 |
CheckFailed(("invalid requirement on flag, " |
| 1705 |
"flag does not have the required value"), |
1705 |
"flag does not have the required value"), |
| 1706 |
Flag); |
1706 |
Flag); |
| 1707 |
continue; |
1707 |
continue; |
| 1708 |
} |
1708 |
} |
| 1709 |
} |
1709 |
} |
| 1710 |
} |
1710 |
} |
| 1711 |
|
1711 |
|
| 1712 |
void |
1712 |
void |
| 1713 |
Verifier::visitModuleFlag(const MDNode *Op, |
1713 |
Verifier::visitModuleFlag(const MDNode *Op, |
| 1714 |
DenseMap &SeenIDs, |
1714 |
DenseMap &SeenIDs, |
| 1715 |
SmallVectorImpl &Requirements) { |
1715 |
SmallVectorImpl &Requirements) { |
| 1716 |
// Each module flag should have three arguments, the merge behavior (a |
1716 |
// Each module flag should have three arguments, the merge behavior (a |
| 1717 |
// constant int), the flag ID (an MDString), and the value. |
1717 |
// constant int), the flag ID (an MDString), and the value. |
| 1718 |
Check(Op->getNumOperands() == 3, |
1718 |
Check(Op->getNumOperands() == 3, |
| 1719 |
"incorrect number of operands in module flag", Op); |
1719 |
"incorrect number of operands in module flag", Op); |
| 1720 |
Module::ModFlagBehavior MFB; |
1720 |
Module::ModFlagBehavior MFB; |
| 1721 |
if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) { |
1721 |
if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) { |
| 1722 |
Check(mdconst::dyn_extract_or_null(Op->getOperand(0)), |
1722 |
Check(mdconst::dyn_extract_or_null(Op->getOperand(0)), |
| 1723 |
"invalid behavior operand in module flag (expected constant integer)", |
1723 |
"invalid behavior operand in module flag (expected constant integer)", |
| 1724 |
Op->getOperand(0)); |
1724 |
Op->getOperand(0)); |
| 1725 |
Check(false, |
1725 |
Check(false, |
| 1726 |
"invalid behavior operand in module flag (unexpected constant)", |
1726 |
"invalid behavior operand in module flag (unexpected constant)", |
| 1727 |
Op->getOperand(0)); |
1727 |
Op->getOperand(0)); |
| 1728 |
} |
1728 |
} |
| 1729 |
MDString *ID = dyn_cast_or_null(Op->getOperand(1)); |
1729 |
MDString *ID = dyn_cast_or_null(Op->getOperand(1)); |
| 1730 |
Check(ID, "invalid ID operand in module flag (expected metadata string)", |
1730 |
Check(ID, "invalid ID operand in module flag (expected metadata string)", |
| 1731 |
Op->getOperand(1)); |
1731 |
Op->getOperand(1)); |
| 1732 |
|
1732 |
|
| 1733 |
// Check the values for behaviors with additional requirements. |
1733 |
// Check the values for behaviors with additional requirements. |
| 1734 |
switch (MFB) { |
1734 |
switch (MFB) { |
| 1735 |
case Module::Error: |
1735 |
case Module::Error: |
| 1736 |
case Module::Warning: |
1736 |
case Module::Warning: |
| 1737 |
case Module::Override: |
1737 |
case Module::Override: |
| 1738 |
// These behavior types accept any value. |
1738 |
// These behavior types accept any value. |
| 1739 |
break; |
1739 |
break; |
| 1740 |
|
1740 |
|
| 1741 |
case Module::Min: { |
1741 |
case Module::Min: { |
| 1742 |
auto *V = mdconst::dyn_extract_or_null(Op->getOperand(2)); |
1742 |
auto *V = mdconst::dyn_extract_or_null(Op->getOperand(2)); |
| 1743 |
Check(V && V->getValue().isNonNegative(), |
1743 |
Check(V && V->getValue().isNonNegative(), |
| 1744 |
"invalid value for 'min' module flag (expected constant non-negative " |
1744 |
"invalid value for 'min' module flag (expected constant non-negative " |
| 1745 |
"integer)", |
1745 |
"integer)", |
| 1746 |
Op->getOperand(2)); |
1746 |
Op->getOperand(2)); |
| 1747 |
break; |
1747 |
break; |
| 1748 |
} |
1748 |
} |
| 1749 |
|
1749 |
|
| 1750 |
case Module::Max: { |
1750 |
case Module::Max: { |
| 1751 |
Check(mdconst::dyn_extract_or_null(Op->getOperand(2)), |
1751 |
Check(mdconst::dyn_extract_or_null(Op->getOperand(2)), |
| 1752 |
"invalid value for 'max' module flag (expected constant integer)", |
1752 |
"invalid value for 'max' module flag (expected constant integer)", |
| 1753 |
Op->getOperand(2)); |
1753 |
Op->getOperand(2)); |
| 1754 |
break; |
1754 |
break; |
| 1755 |
} |
1755 |
} |
| 1756 |
|
1756 |
|
| 1757 |
case Module::Require: { |
1757 |
case Module::Require: { |
| 1758 |
// The value should itself be an MDNode with two operands, a flag ID (an |
1758 |
// The value should itself be an MDNode with two operands, a flag ID (an |
| 1759 |
// MDString), and a value. |
1759 |
// MDString), and a value. |
| 1760 |
MDNode *Value = dyn_cast(Op->getOperand(2)); |
1760 |
MDNode *Value = dyn_cast(Op->getOperand(2)); |
| 1761 |
Check(Value && Value->getNumOperands() == 2, |
1761 |
Check(Value && Value->getNumOperands() == 2, |
| 1762 |
"invalid value for 'require' module flag (expected metadata pair)", |
1762 |
"invalid value for 'require' module flag (expected metadata pair)", |
| 1763 |
Op->getOperand(2)); |
1763 |
Op->getOperand(2)); |
| 1764 |
Check(isa(Value->getOperand(0)), |
1764 |
Check(isa(Value->getOperand(0)), |
| 1765 |
("invalid value for 'require' module flag " |
1765 |
("invalid value for 'require' module flag " |
| 1766 |
"(first value operand should be a string)"), |
1766 |
"(first value operand should be a string)"), |
| 1767 |
Value->getOperand(0)); |
1767 |
Value->getOperand(0)); |
| 1768 |
|
1768 |
|
| 1769 |
// Append it to the list of requirements, to check once all module flags are |
1769 |
// Append it to the list of requirements, to check once all module flags are |
| 1770 |
// scanned. |
1770 |
// scanned. |
| 1771 |
Requirements.push_back(Value); |
1771 |
Requirements.push_back(Value); |
| 1772 |
break; |
1772 |
break; |
| 1773 |
} |
1773 |
} |
| 1774 |
|
1774 |
|
| 1775 |
case Module::Append: |
1775 |
case Module::Append: |
| 1776 |
case Module::AppendUnique: { |
1776 |
case Module::AppendUnique: { |
| 1777 |
// These behavior types require the operand be an MDNode. |
1777 |
// These behavior types require the operand be an MDNode. |
| 1778 |
Check(isa(Op->getOperand(2)), |
1778 |
Check(isa(Op->getOperand(2)), |
| 1779 |
"invalid value for 'append'-type module flag " |
1779 |
"invalid value for 'append'-type module flag " |
| 1780 |
"(expected a metadata node)", |
1780 |
"(expected a metadata node)", |
| 1781 |
Op->getOperand(2)); |
1781 |
Op->getOperand(2)); |
| 1782 |
break; |
1782 |
break; |
| 1783 |
} |
1783 |
} |
| 1784 |
} |
1784 |
} |
| 1785 |
|
1785 |
|
| 1786 |
// Unless this is a "requires" flag, check the ID is unique. |
1786 |
// Unless this is a "requires" flag, check the ID is unique. |
| 1787 |
if (MFB != Module::Require) { |
1787 |
if (MFB != Module::Require) { |
| 1788 |
bool Inserted = SeenIDs.insert(std::make_pair(ID, Op)).second; |
1788 |
bool Inserted = SeenIDs.insert(std::make_pair(ID, Op)).second; |
| 1789 |
Check(Inserted, |
1789 |
Check(Inserted, |
| 1790 |
"module flag identifiers must be unique (or of 'require' type)", ID); |
1790 |
"module flag identifiers must be unique (or of 'require' type)", ID); |
| 1791 |
} |
1791 |
} |
| 1792 |
|
1792 |
|
| 1793 |
if (ID->getString() == "wchar_size") { |
1793 |
if (ID->getString() == "wchar_size") { |
| 1794 |
ConstantInt *Value |
1794 |
ConstantInt *Value |
| 1795 |
= mdconst::dyn_extract_or_null(Op->getOperand(2)); |
1795 |
= mdconst::dyn_extract_or_null(Op->getOperand(2)); |
| 1796 |
Check(Value, "wchar_size metadata requires constant integer argument"); |
1796 |
Check(Value, "wchar_size metadata requires constant integer argument"); |
| 1797 |
} |
1797 |
} |
| 1798 |
|
1798 |
|
| 1799 |
if (ID->getString() == "Linker Options") { |
1799 |
if (ID->getString() == "Linker Options") { |
| 1800 |
// If the llvm.linker.options named metadata exists, we assume that the |
1800 |
// If the llvm.linker.options named metadata exists, we assume that the |
| 1801 |
// bitcode reader has upgraded the module flag. Otherwise the flag might |
1801 |
// bitcode reader has upgraded the module flag. Otherwise the flag might |
| 1802 |
// have been created by a client directly. |
1802 |
// have been created by a client directly. |
| 1803 |
Check(M.getNamedMetadata("llvm.linker.options"), |
1803 |
Check(M.getNamedMetadata("llvm.linker.options"), |
| 1804 |
"'Linker Options' named metadata no longer supported"); |
1804 |
"'Linker Options' named metadata no longer supported"); |
| 1805 |
} |
1805 |
} |
| 1806 |
|
1806 |
|
| 1807 |
if (ID->getString() == "SemanticInterposition") { |
1807 |
if (ID->getString() == "SemanticInterposition") { |
| 1808 |
ConstantInt *Value = |
1808 |
ConstantInt *Value = |
| 1809 |
mdconst::dyn_extract_or_null(Op->getOperand(2)); |
1809 |
mdconst::dyn_extract_or_null(Op->getOperand(2)); |
| 1810 |
Check(Value, |
1810 |
Check(Value, |
| 1811 |
"SemanticInterposition metadata requires constant integer argument"); |
1811 |
"SemanticInterposition metadata requires constant integer argument"); |
| 1812 |
} |
1812 |
} |
| 1813 |
|
1813 |
|
| 1814 |
if (ID->getString() == "CG Profile") { |
1814 |
if (ID->getString() == "CG Profile") { |
| 1815 |
for (const MDOperand &MDO : cast(Op->getOperand(2))->operands()) |
1815 |
for (const MDOperand &MDO : cast(Op->getOperand(2))->operands()) |
| 1816 |
visitModuleFlagCGProfileEntry(MDO); |
1816 |
visitModuleFlagCGProfileEntry(MDO); |
| 1817 |
} |
1817 |
} |
| 1818 |
} |
1818 |
} |
| 1819 |
|
1819 |
|
| 1820 |
void Verifier::visitModuleFlagCGProfileEntry(const MDOperand &MDO) { |
1820 |
void Verifier::visitModuleFlagCGProfileEntry(const MDOperand &MDO) { |
| 1821 |
auto CheckFunction = [&](const MDOperand &FuncMDO) { |
1821 |
auto CheckFunction = [&](const MDOperand &FuncMDO) { |
| 1822 |
if (!FuncMDO) |
1822 |
if (!FuncMDO) |
| 1823 |
return; |
1823 |
return; |
| 1824 |
auto F = dyn_cast(FuncMDO); |
1824 |
auto F = dyn_cast(FuncMDO); |
| 1825 |
Check(F && isa(F->getValue()->stripPointerCasts()), |
1825 |
Check(F && isa(F->getValue()->stripPointerCasts()), |
| 1826 |
"expected a Function or null", FuncMDO); |
1826 |
"expected a Function or null", FuncMDO); |
| 1827 |
}; |
1827 |
}; |
| 1828 |
auto Node = dyn_cast_or_null(MDO); |
1828 |
auto Node = dyn_cast_or_null(MDO); |
| 1829 |
Check(Node && Node->getNumOperands() == 3, "expected a MDNode triple", MDO); |
1829 |
Check(Node && Node->getNumOperands() == 3, "expected a MDNode triple", MDO); |
| 1830 |
CheckFunction(Node->getOperand(0)); |
1830 |
CheckFunction(Node->getOperand(0)); |
| 1831 |
CheckFunction(Node->getOperand(1)); |
1831 |
CheckFunction(Node->getOperand(1)); |
| 1832 |
auto Count = dyn_cast_or_null(Node->getOperand(2)); |
1832 |
auto Count = dyn_cast_or_null(Node->getOperand(2)); |
| 1833 |
Check(Count && Count->getType()->isIntegerTy(), |
1833 |
Check(Count && Count->getType()->isIntegerTy(), |
| 1834 |
"expected an integer constant", Node->getOperand(2)); |
1834 |
"expected an integer constant", Node->getOperand(2)); |
| 1835 |
} |
1835 |
} |
| 1836 |
|
1836 |
|
| 1837 |
void Verifier::verifyAttributeTypes(AttributeSet Attrs, const Value *V) { |
1837 |
void Verifier::verifyAttributeTypes(AttributeSet Attrs, const Value *V) { |
| 1838 |
for (Attribute A : Attrs) { |
1838 |
for (Attribute A : Attrs) { |
| 1839 |
|
1839 |
|
| 1840 |
if (A.isStringAttribute()) { |
1840 |
if (A.isStringAttribute()) { |
| 1841 |
#define GET_ATTR_NAMES |
1841 |
#define GET_ATTR_NAMES |
| 1842 |
#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) |
1842 |
#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) |
| 1843 |
#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \ |
1843 |
#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \ |
| 1844 |
if (A.getKindAsString() == #DISPLAY_NAME) { \ |
1844 |
if (A.getKindAsString() == #DISPLAY_NAME) { \ |
| 1845 |
auto V = A.getValueAsString(); \ |
1845 |
auto V = A.getValueAsString(); \ |
| 1846 |
if (!(V.empty() || V == "true" || V == "false")) \ |
1846 |
if (!(V.empty() || V == "true" || V == "false")) \ |
| 1847 |
CheckFailed("invalid value for '" #DISPLAY_NAME "' attribute: " + V + \ |
1847 |
CheckFailed("invalid value for '" #DISPLAY_NAME "' attribute: " + V + \ |
| 1848 |
""); \ |
1848 |
""); \ |
| 1849 |
} |
1849 |
} |
| 1850 |
|
1850 |
|
| 1851 |
#include "llvm/IR/Attributes.inc" |
1851 |
#include "llvm/IR/Attributes.inc" |
| 1852 |
continue; |
1852 |
continue; |
| 1853 |
} |
1853 |
} |
| 1854 |
|
1854 |
|
| 1855 |
if (A.isIntAttribute() != Attribute::isIntAttrKind(A.getKindAsEnum())) { |
1855 |
if (A.isIntAttribute() != Attribute::isIntAttrKind(A.getKindAsEnum())) { |
| 1856 |
CheckFailed("Attribute '" + A.getAsString() + "' should have an Argument", |
1856 |
CheckFailed("Attribute '" + A.getAsString() + "' should have an Argument", |
| 1857 |
V); |
1857 |
V); |
| 1858 |
return; |
1858 |
return; |
| 1859 |
} |
1859 |
} |
| 1860 |
} |
1860 |
} |
| 1861 |
} |
1861 |
} |
| 1862 |
|
1862 |
|
| 1863 |
// VerifyParameterAttrs - Check the given attributes for an argument or return |
1863 |
// VerifyParameterAttrs - Check the given attributes for an argument or return |
| 1864 |
// value of the specified type. The value V is printed in error messages. |
1864 |
// value of the specified type. The value V is printed in error messages. |
| 1865 |
void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty, |
1865 |
void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty, |
| 1866 |
const Value *V) { |
1866 |
const Value *V) { |
| 1867 |
if (!Attrs.hasAttributes()) |
1867 |
if (!Attrs.hasAttributes()) |
| 1868 |
return; |
1868 |
return; |
| 1869 |
|
1869 |
|
| 1870 |
verifyAttributeTypes(Attrs, V); |
1870 |
verifyAttributeTypes(Attrs, V); |
| 1871 |
|
1871 |
|
| 1872 |
for (Attribute Attr : Attrs) |
1872 |
for (Attribute Attr : Attrs) |
| 1873 |
Check(Attr.isStringAttribute() || |
1873 |
Check(Attr.isStringAttribute() || |
| 1874 |
Attribute::canUseAsParamAttr(Attr.getKindAsEnum()), |
1874 |
Attribute::canUseAsParamAttr(Attr.getKindAsEnum()), |
| 1875 |
"Attribute '" + Attr.getAsString() + "' does not apply to parameters", |
1875 |
"Attribute '" + Attr.getAsString() + "' does not apply to parameters", |
| 1876 |
V); |
1876 |
V); |
| 1877 |
|
1877 |
|
| 1878 |
if (Attrs.hasAttribute(Attribute::ImmArg)) { |
1878 |
if (Attrs.hasAttribute(Attribute::ImmArg)) { |
| 1879 |
Check(Attrs.getNumAttributes() == 1, |
1879 |
Check(Attrs.getNumAttributes() == 1, |
| 1880 |
"Attribute 'immarg' is incompatible with other attributes", V); |
1880 |
"Attribute 'immarg' is incompatible with other attributes", V); |
| 1881 |
} |
1881 |
} |
| 1882 |
|
1882 |
|
| 1883 |
// Check for mutually incompatible attributes. Only inreg is compatible with |
1883 |
// Check for mutually incompatible attributes. Only inreg is compatible with |
| 1884 |
// sret. |
1884 |
// sret. |
| 1885 |
unsigned AttrCount = 0; |
1885 |
unsigned AttrCount = 0; |
| 1886 |
AttrCount += Attrs.hasAttribute(Attribute::ByVal); |
1886 |
AttrCount += Attrs.hasAttribute(Attribute::ByVal); |
| 1887 |
AttrCount += Attrs.hasAttribute(Attribute::InAlloca); |
1887 |
AttrCount += Attrs.hasAttribute(Attribute::InAlloca); |
| 1888 |
AttrCount += Attrs.hasAttribute(Attribute::Preallocated); |
1888 |
AttrCount += Attrs.hasAttribute(Attribute::Preallocated); |
| 1889 |
AttrCount += Attrs.hasAttribute(Attribute::StructRet) || |
1889 |
AttrCount += Attrs.hasAttribute(Attribute::StructRet) || |
| 1890 |
Attrs.hasAttribute(Attribute::InReg); |
1890 |
Attrs.hasAttribute(Attribute::InReg); |
| 1891 |
AttrCount += Attrs.hasAttribute(Attribute::Nest); |
1891 |
AttrCount += Attrs.hasAttribute(Attribute::Nest); |
| 1892 |
AttrCount += Attrs.hasAttribute(Attribute::ByRef); |
1892 |
AttrCount += Attrs.hasAttribute(Attribute::ByRef); |
| 1893 |
Check(AttrCount <= 1, |
1893 |
Check(AttrCount <= 1, |
| 1894 |
"Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', " |
1894 |
"Attributes 'byval', 'inalloca', 'preallocated', 'inreg', 'nest', " |
| 1895 |
"'byref', and 'sret' are incompatible!", |
1895 |
"'byref', and 'sret' are incompatible!", |
| 1896 |
V); |
1896 |
V); |
| 1897 |
|
1897 |
|
| 1898 |
Check(!(Attrs.hasAttribute(Attribute::InAlloca) && |
1898 |
Check(!(Attrs.hasAttribute(Attribute::InAlloca) && |
| 1899 |
Attrs.hasAttribute(Attribute::ReadOnly)), |
1899 |
Attrs.hasAttribute(Attribute::ReadOnly)), |
| 1900 |
"Attributes " |
1900 |
"Attributes " |
| 1901 |
"'inalloca and readonly' are incompatible!", |
1901 |
"'inalloca and readonly' are incompatible!", |
| 1902 |
V); |
1902 |
V); |
| 1903 |
|
1903 |
|
| 1904 |
Check(!(Attrs.hasAttribute(Attribute::StructRet) && |
1904 |
Check(!(Attrs.hasAttribute(Attribute::StructRet) && |
| 1905 |
Attrs.hasAttribute(Attribute::Returned)), |
1905 |
Attrs.hasAttribute(Attribute::Returned)), |
| 1906 |
"Attributes " |
1906 |
"Attributes " |
| 1907 |
"'sret and returned' are incompatible!", |
1907 |
"'sret and returned' are incompatible!", |
| 1908 |
V); |
1908 |
V); |
| 1909 |
|
1909 |
|
| 1910 |
Check(!(Attrs.hasAttribute(Attribute::ZExt) && |
1910 |
Check(!(Attrs.hasAttribute(Attribute::ZExt) && |
| 1911 |
Attrs.hasAttribute(Attribute::SExt)), |
1911 |
Attrs.hasAttribute(Attribute::SExt)), |
| 1912 |
"Attributes " |
1912 |
"Attributes " |
| 1913 |
"'zeroext and signext' are incompatible!", |
1913 |
"'zeroext and signext' are incompatible!", |
| 1914 |
V); |
1914 |
V); |
| 1915 |
|
1915 |
|
| 1916 |
Check(!(Attrs.hasAttribute(Attribute::ReadNone) && |
1916 |
Check(!(Attrs.hasAttribute(Attribute::ReadNone) && |
| 1917 |
Attrs.hasAttribute(Attribute::ReadOnly)), |
1917 |
Attrs.hasAttribute(Attribute::ReadOnly)), |
| 1918 |
"Attributes " |
1918 |
"Attributes " |
| 1919 |
"'readnone and readonly' are incompatible!", |
1919 |
"'readnone and readonly' are incompatible!", |
| 1920 |
V); |
1920 |
V); |
| 1921 |
|
1921 |
|
| 1922 |
Check(!(Attrs.hasAttribute(Attribute::ReadNone) && |
1922 |
Check(!(Attrs.hasAttribute(Attribute::ReadNone) && |
| 1923 |
Attrs.hasAttribute(Attribute::WriteOnly)), |
1923 |
Attrs.hasAttribute(Attribute::WriteOnly)), |
| 1924 |
"Attributes " |
1924 |
"Attributes " |
| 1925 |
"'readnone and writeonly' are incompatible!", |
1925 |
"'readnone and writeonly' are incompatible!", |
| 1926 |
V); |
1926 |
V); |
| 1927 |
|
1927 |
|
| 1928 |
Check(!(Attrs.hasAttribute(Attribute::ReadOnly) && |
1928 |
Check(!(Attrs.hasAttribute(Attribute::ReadOnly) && |
| 1929 |
Attrs.hasAttribute(Attribute::WriteOnly)), |
1929 |
Attrs.hasAttribute(Attribute::WriteOnly)), |
| 1930 |
"Attributes " |
1930 |
"Attributes " |
| 1931 |
"'readonly and writeonly' are incompatible!", |
1931 |
"'readonly and writeonly' are incompatible!", |
| 1932 |
V); |
1932 |
V); |
| 1933 |
|
1933 |
|
| 1934 |
Check(!(Attrs.hasAttribute(Attribute::NoInline) && |
1934 |
Check(!(Attrs.hasAttribute(Attribute::NoInline) && |
| 1935 |
Attrs.hasAttribute(Attribute::AlwaysInline)), |
1935 |
Attrs.hasAttribute(Attribute::AlwaysInline)), |
| 1936 |
"Attributes " |
1936 |
"Attributes " |
| 1937 |
"'noinline and alwaysinline' are incompatible!", |
1937 |
"'noinline and alwaysinline' are incompatible!", |
| 1938 |
V); |
1938 |
V); |
| 1939 |
|
1939 |
|
| 1940 |
AttributeMask IncompatibleAttrs = AttributeFuncs::typeIncompatible(Ty); |
1940 |
AttributeMask IncompatibleAttrs = AttributeFuncs::typeIncompatible(Ty); |
| 1941 |
for (Attribute Attr : Attrs) { |
1941 |
for (Attribute Attr : Attrs) { |
| 1942 |
if (!Attr.isStringAttribute() && |
1942 |
if (!Attr.isStringAttribute() && |
| 1943 |
IncompatibleAttrs.contains(Attr.getKindAsEnum())) { |
1943 |
IncompatibleAttrs.contains(Attr.getKindAsEnum())) { |
| 1944 |
CheckFailed("Attribute '" + Attr.getAsString() + |
1944 |
CheckFailed("Attribute '" + Attr.getAsString() + |
| 1945 |
"' applied to incompatible type!", V); |
1945 |
"' applied to incompatible type!", V); |
| 1946 |
return; |
1946 |
return; |
| 1947 |
} |
1947 |
} |
| 1948 |
} |
1948 |
} |
| 1949 |
|
1949 |
|
| 1950 |
if (isa(Ty)) { |
1950 |
if (isa(Ty)) { |
| 1951 |
if (Attrs.hasAttribute(Attribute::ByVal)) { |
1951 |
if (Attrs.hasAttribute(Attribute::ByVal)) { |
| 1952 |
if (Attrs.hasAttribute(Attribute::Alignment)) { |
1952 |
if (Attrs.hasAttribute(Attribute::Alignment)) { |
| 1953 |
Align AttrAlign = Attrs.getAlignment().valueOrOne(); |
1953 |
Align AttrAlign = Attrs.getAlignment().valueOrOne(); |
| 1954 |
Align MaxAlign(ParamMaxAlignment); |
1954 |
Align MaxAlign(ParamMaxAlignment); |
| 1955 |
Check(AttrAlign <= MaxAlign, |
1955 |
Check(AttrAlign <= MaxAlign, |
| 1956 |
"Attribute 'align' exceed the max size 2^14", V); |
1956 |
"Attribute 'align' exceed the max size 2^14", V); |
| 1957 |
} |
1957 |
} |
| 1958 |
SmallPtrSet Visited; |
1958 |
SmallPtrSet Visited; |
| 1959 |
Check(Attrs.getByValType()->isSized(&Visited), |
1959 |
Check(Attrs.getByValType()->isSized(&Visited), |
| 1960 |
"Attribute 'byval' does not support unsized types!", V); |
1960 |
"Attribute 'byval' does not support unsized types!", V); |
| 1961 |
} |
1961 |
} |
| 1962 |
if (Attrs.hasAttribute(Attribute::ByRef)) { |
1962 |
if (Attrs.hasAttribute(Attribute::ByRef)) { |
| 1963 |
SmallPtrSet Visited; |
1963 |
SmallPtrSet Visited; |
| 1964 |
Check(Attrs.getByRefType()->isSized(&Visited), |
1964 |
Check(Attrs.getByRefType()->isSized(&Visited), |
| 1965 |
"Attribute 'byref' does not support unsized types!", V); |
1965 |
"Attribute 'byref' does not support unsized types!", V); |
| 1966 |
} |
1966 |
} |
| 1967 |
if (Attrs.hasAttribute(Attribute::InAlloca)) { |
1967 |
if (Attrs.hasAttribute(Attribute::InAlloca)) { |
| 1968 |
SmallPtrSet Visited; |
1968 |
SmallPtrSet Visited; |
| 1969 |
Check(Attrs.getInAllocaType()->isSized(&Visited), |
1969 |
Check(Attrs.getInAllocaType()->isSized(&Visited), |
| 1970 |
"Attribute 'inalloca' does not support unsized types!", V); |
1970 |
"Attribute 'inalloca' does not support unsized types!", V); |
| 1971 |
} |
1971 |
} |
| 1972 |
if (Attrs.hasAttribute(Attribute::Preallocated)) { |
1972 |
if (Attrs.hasAttribute(Attribute::Preallocated)) { |
| 1973 |
SmallPtrSet Visited; |
1973 |
SmallPtrSet Visited; |
| 1974 |
Check(Attrs.getPreallocatedType()->isSized(&Visited), |
1974 |
Check(Attrs.getPreallocatedType()->isSized(&Visited), |
| 1975 |
"Attribute 'preallocated' does not support unsized types!", V); |
1975 |
"Attribute 'preallocated' does not support unsized types!", V); |
| 1976 |
} |
1976 |
} |
| 1977 |
} |
1977 |
} |
| 1978 |
|
1978 |
|
| 1979 |
if (Attrs.hasAttribute(Attribute::NoFPClass)) { |
1979 |
if (Attrs.hasAttribute(Attribute::NoFPClass)) { |
| 1980 |
uint64_t Val = Attrs.getAttribute(Attribute::NoFPClass).getValueAsInt(); |
1980 |
uint64_t Val = Attrs.getAttribute(Attribute::NoFPClass).getValueAsInt(); |
| 1981 |
Check(Val != 0, "Attribute 'nofpclass' must have at least one test bit set", |
1981 |
Check(Val != 0, "Attribute 'nofpclass' must have at least one test bit set", |
| 1982 |
V); |
1982 |
V); |
| 1983 |
Check((Val & ~static_cast(fcAllFlags)) == 0, |
1983 |
Check((Val & ~static_cast(fcAllFlags)) == 0, |
| 1984 |
"Invalid value for 'nofpclass' test mask", V); |
1984 |
"Invalid value for 'nofpclass' test mask", V); |
| 1985 |
} |
1985 |
} |
| 1986 |
} |
1986 |
} |
| 1987 |
|
1987 |
|
| 1988 |
void Verifier::checkUnsignedBaseTenFuncAttr(AttributeList Attrs, StringRef Attr, |
1988 |
void Verifier::checkUnsignedBaseTenFuncAttr(AttributeList Attrs, StringRef Attr, |
| 1989 |
const Value *V) { |
1989 |
const Value *V) { |
| 1990 |
if (Attrs.hasFnAttr(Attr)) { |
1990 |
if (Attrs.hasFnAttr(Attr)) { |
| 1991 |
StringRef S = Attrs.getFnAttr(Attr).getValueAsString(); |
1991 |
StringRef S = Attrs.getFnAttr(Attr).getValueAsString(); |
| 1992 |
unsigned N; |
1992 |
unsigned N; |
| 1993 |
if (S.getAsInteger(10, N)) |
1993 |
if (S.getAsInteger(10, N)) |
| 1994 |
CheckFailed("\"" + Attr + "\" takes an unsigned integer: " + S, V); |
1994 |
CheckFailed("\"" + Attr + "\" takes an unsigned integer: " + S, V); |
| 1995 |
} |
1995 |
} |
| 1996 |
} |
1996 |
} |
| 1997 |
|
1997 |
|
| 1998 |
// Check parameter attributes against a function type. |
1998 |
// Check parameter attributes against a function type. |
| 1999 |
// The value V is printed in error messages. |
1999 |
// The value V is printed in error messages. |
| 2000 |
void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, |
2000 |
void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, |
| 2001 |
const Value *V, bool IsIntrinsic, |
2001 |
const Value *V, bool IsIntrinsic, |
| 2002 |
bool IsInlineAsm) { |
2002 |
bool IsInlineAsm) { |
| 2003 |
if (Attrs.isEmpty()) |
2003 |
if (Attrs.isEmpty()) |
| 2004 |
return; |
2004 |
return; |
| 2005 |
|
2005 |
|
| 2006 |
if (AttributeListsVisited.insert(Attrs.getRawPointer()).second) { |
2006 |
if (AttributeListsVisited.insert(Attrs.getRawPointer()).second) { |
| 2007 |
Check(Attrs.hasParentContext(Context), |
2007 |
Check(Attrs.hasParentContext(Context), |
| 2008 |
"Attribute list does not match Module context!", &Attrs, V); |
2008 |
"Attribute list does not match Module context!", &Attrs, V); |
| 2009 |
for (const auto &AttrSet : Attrs) { |
2009 |
for (const auto &AttrSet : Attrs) { |
| 2010 |
Check(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context), |
2010 |
Check(!AttrSet.hasAttributes() || AttrSet.hasParentContext(Context), |
| 2011 |
"Attribute set does not match Module context!", &AttrSet, V); |
2011 |
"Attribute set does not match Module context!", &AttrSet, V); |
| 2012 |
for (const auto &A : AttrSet) { |
2012 |
for (const auto &A : AttrSet) { |
| 2013 |
Check(A.hasParentContext(Context), |
2013 |
Check(A.hasParentContext(Context), |
| 2014 |
"Attribute does not match Module context!", &A, V); |
2014 |
"Attribute does not match Module context!", &A, V); |
| 2015 |
} |
2015 |
} |
| 2016 |
} |
2016 |
} |
| 2017 |
} |
2017 |
} |
| 2018 |
|
2018 |
|
| 2019 |
bool SawNest = false; |
2019 |
bool SawNest = false; |
| 2020 |
bool SawReturned = false; |
2020 |
bool SawReturned = false; |
| 2021 |
bool SawSRet = false; |
2021 |
bool SawSRet = false; |
| 2022 |
bool SawSwiftSelf = false; |
2022 |
bool SawSwiftSelf = false; |
| 2023 |
bool SawSwiftAsync = false; |
2023 |
bool SawSwiftAsync = false; |
| 2024 |
bool SawSwiftError = false; |
2024 |
bool SawSwiftError = false; |
| 2025 |
|
2025 |
|
| 2026 |
// Verify return value attributes. |
2026 |
// Verify return value attributes. |
| 2027 |
AttributeSet RetAttrs = Attrs.getRetAttrs(); |
2027 |
AttributeSet RetAttrs = Attrs.getRetAttrs(); |
| 2028 |
for (Attribute RetAttr : RetAttrs) |
2028 |
for (Attribute RetAttr : RetAttrs) |
| 2029 |
Check(RetAttr.isStringAttribute() || |
2029 |
Check(RetAttr.isStringAttribute() || |
| 2030 |
Attribute::canUseAsRetAttr(RetAttr.getKindAsEnum()), |
2030 |
Attribute::canUseAsRetAttr(RetAttr.getKindAsEnum()), |
| 2031 |
"Attribute '" + RetAttr.getAsString() + |
2031 |
"Attribute '" + RetAttr.getAsString() + |
| 2032 |
"' does not apply to function return values", |
2032 |
"' does not apply to function return values", |
| 2033 |
V); |
2033 |
V); |
| 2034 |
|
2034 |
|
| 2035 |
verifyParameterAttrs(RetAttrs, FT->getReturnType(), V); |
2035 |
verifyParameterAttrs(RetAttrs, FT->getReturnType(), V); |
| 2036 |
|
2036 |
|
| 2037 |
// Verify parameter attributes. |
2037 |
// Verify parameter attributes. |
| 2038 |
for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { |
2038 |
for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { |
| 2039 |
Type *Ty = FT->getParamType(i); |
2039 |
Type *Ty = FT->getParamType(i); |
| 2040 |
AttributeSet ArgAttrs = Attrs.getParamAttrs(i); |
2040 |
AttributeSet ArgAttrs = Attrs.getParamAttrs(i); |
| 2041 |
|
2041 |
|
| 2042 |
if (!IsIntrinsic) { |
2042 |
if (!IsIntrinsic) { |
| 2043 |
Check(!ArgAttrs.hasAttribute(Attribute::ImmArg), |
2043 |
Check(!ArgAttrs.hasAttribute(Attribute::ImmArg), |
| 2044 |
"immarg attribute only applies to intrinsics", V); |
2044 |
"immarg attribute only applies to intrinsics", V); |
| 2045 |
if (!IsInlineAsm) |
2045 |
if (!IsInlineAsm) |
| 2046 |
Check(!ArgAttrs.hasAttribute(Attribute::ElementType), |
2046 |
Check(!ArgAttrs.hasAttribute(Attribute::ElementType), |
| 2047 |
"Attribute 'elementtype' can only be applied to intrinsics" |
2047 |
"Attribute 'elementtype' can only be applied to intrinsics" |
| 2048 |
" and inline asm.", |
2048 |
" and inline asm.", |
| 2049 |
V); |
2049 |
V); |
| 2050 |
} |
2050 |
} |
| 2051 |
|
2051 |
|
| 2052 |
verifyParameterAttrs(ArgAttrs, Ty, V); |
2052 |
verifyParameterAttrs(ArgAttrs, Ty, V); |
| 2053 |
|
2053 |
|
| 2054 |
if (ArgAttrs.hasAttribute(Attribute::Nest)) { |
2054 |
if (ArgAttrs.hasAttribute(Attribute::Nest)) { |
| 2055 |
Check(!SawNest, "More than one parameter has attribute nest!", V); |
2055 |
Check(!SawNest, "More than one parameter has attribute nest!", V); |
| 2056 |
SawNest = true; |
2056 |
SawNest = true; |
| 2057 |
} |
2057 |
} |
| 2058 |
|
2058 |
|
| 2059 |
if (ArgAttrs.hasAttribute(Attribute::Returned)) { |
2059 |
if (ArgAttrs.hasAttribute(Attribute::Returned)) { |
| 2060 |
Check(!SawReturned, "More than one parameter has attribute returned!", V); |
2060 |
Check(!SawReturned, "More than one parameter has attribute returned!", V); |
| 2061 |
Check(Ty->canLosslesslyBitCastTo(FT->getReturnType()), |
2061 |
Check(Ty->canLosslesslyBitCastTo(FT->getReturnType()), |
| 2062 |
"Incompatible argument and return types for 'returned' attribute", |
2062 |
"Incompatible argument and return types for 'returned' attribute", |
| 2063 |
V); |
2063 |
V); |
| 2064 |
SawReturned = true; |
2064 |
SawReturned = true; |
| 2065 |
} |
2065 |
} |
| 2066 |
|
2066 |
|
| 2067 |
if (ArgAttrs.hasAttribute(Attribute::StructRet)) { |
2067 |
if (ArgAttrs.hasAttribute(Attribute::StructRet)) { |
| 2068 |
Check(!SawSRet, "Cannot have multiple 'sret' parameters!", V); |
2068 |
Check(!SawSRet, "Cannot have multiple 'sret' parameters!", V); |
| 2069 |
Check(i == 0 || i == 1, |
2069 |
Check(i == 0 || i == 1, |
| 2070 |
"Attribute 'sret' is not on first or second parameter!", V); |
2070 |
"Attribute 'sret' is not on first or second parameter!", V); |
| 2071 |
SawSRet = true; |
2071 |
SawSRet = true; |
| 2072 |
} |
2072 |
} |
| 2073 |
|
2073 |
|
| 2074 |
if (ArgAttrs.hasAttribute(Attribute::SwiftSelf)) { |
2074 |
if (ArgAttrs.hasAttribute(Attribute::SwiftSelf)) { |
| 2075 |
Check(!SawSwiftSelf, "Cannot have multiple 'swiftself' parameters!", V); |
2075 |
Check(!SawSwiftSelf, "Cannot have multiple 'swiftself' parameters!", V); |
| 2076 |
SawSwiftSelf = true; |
2076 |
SawSwiftSelf = true; |
| 2077 |
} |
2077 |
} |
| 2078 |
|
2078 |
|
| 2079 |
if (ArgAttrs.hasAttribute(Attribute::SwiftAsync)) { |
2079 |
if (ArgAttrs.hasAttribute(Attribute::SwiftAsync)) { |
| 2080 |
Check(!SawSwiftAsync, "Cannot have multiple 'swiftasync' parameters!", V); |
2080 |
Check(!SawSwiftAsync, "Cannot have multiple 'swiftasync' parameters!", V); |
| 2081 |
SawSwiftAsync = true; |
2081 |
SawSwiftAsync = true; |
| 2082 |
} |
2082 |
} |
| 2083 |
|
2083 |
|
| 2084 |
if (ArgAttrs.hasAttribute(Attribute::SwiftError)) { |
2084 |
if (ArgAttrs.hasAttribute(Attribute::SwiftError)) { |
| 2085 |
Check(!SawSwiftError, "Cannot have multiple 'swifterror' parameters!", V); |
2085 |
Check(!SawSwiftError, "Cannot have multiple 'swifterror' parameters!", V); |
| 2086 |
SawSwiftError = true; |
2086 |
SawSwiftError = true; |
| 2087 |
} |
2087 |
} |
| 2088 |
|
2088 |
|
| 2089 |
if (ArgAttrs.hasAttribute(Attribute::InAlloca)) { |
2089 |
if (ArgAttrs.hasAttribute(Attribute::InAlloca)) { |
| 2090 |
Check(i == FT->getNumParams() - 1, |
2090 |
Check(i == FT->getNumParams() - 1, |
| 2091 |
"inalloca isn't on the last parameter!", V); |
2091 |
"inalloca isn't on the last parameter!", V); |
| 2092 |
} |
2092 |
} |
| 2093 |
} |
2093 |
} |
| 2094 |
|
2094 |
|
| 2095 |
if (!Attrs.hasFnAttrs()) |
2095 |
if (!Attrs.hasFnAttrs()) |
| 2096 |
return; |
2096 |
return; |
| 2097 |
|
2097 |
|
| 2098 |
verifyAttributeTypes(Attrs.getFnAttrs(), V); |
2098 |
verifyAttributeTypes(Attrs.getFnAttrs(), V); |
| 2099 |
for (Attribute FnAttr : Attrs.getFnAttrs()) |
2099 |
for (Attribute FnAttr : Attrs.getFnAttrs()) |
| 2100 |
Check(FnAttr.isStringAttribute() || |
2100 |
Check(FnAttr.isStringAttribute() || |
| 2101 |
Attribute::canUseAsFnAttr(FnAttr.getKindAsEnum()), |
2101 |
Attribute::canUseAsFnAttr(FnAttr.getKindAsEnum()), |
| 2102 |
"Attribute '" + FnAttr.getAsString() + |
2102 |
"Attribute '" + FnAttr.getAsString() + |
| 2103 |
"' does not apply to functions!", |
2103 |
"' does not apply to functions!", |
| 2104 |
V); |
2104 |
V); |
| 2105 |
|
2105 |
|
| 2106 |
Check(!(Attrs.hasFnAttr(Attribute::NoInline) && |
2106 |
Check(!(Attrs.hasFnAttr(Attribute::NoInline) && |
| 2107 |
Attrs.hasFnAttr(Attribute::AlwaysInline)), |
2107 |
Attrs.hasFnAttr(Attribute::AlwaysInline)), |
| 2108 |
"Attributes 'noinline and alwaysinline' are incompatible!", V); |
2108 |
"Attributes 'noinline and alwaysinline' are incompatible!", V); |
| 2109 |
|
2109 |
|
| 2110 |
if (Attrs.hasFnAttr(Attribute::OptimizeNone)) { |
2110 |
if (Attrs.hasFnAttr(Attribute::OptimizeNone)) { |
| 2111 |
Check(Attrs.hasFnAttr(Attribute::NoInline), |
2111 |
Check(Attrs.hasFnAttr(Attribute::NoInline), |
| 2112 |
"Attribute 'optnone' requires 'noinline'!", V); |
2112 |
"Attribute 'optnone' requires 'noinline'!", V); |
| 2113 |
|
2113 |
|
| 2114 |
Check(!Attrs.hasFnAttr(Attribute::OptimizeForSize), |
2114 |
Check(!Attrs.hasFnAttr(Attribute::OptimizeForSize), |
| 2115 |
"Attributes 'optsize and optnone' are incompatible!", V); |
2115 |
"Attributes 'optsize and optnone' are incompatible!", V); |
| 2116 |
|
2116 |
|
| 2117 |
Check(!Attrs.hasFnAttr(Attribute::MinSize), |
2117 |
Check(!Attrs.hasFnAttr(Attribute::MinSize), |
| 2118 |
"Attributes 'minsize and optnone' are incompatible!", V); |
2118 |
"Attributes 'minsize and optnone' are incompatible!", V); |
| 2119 |
} |
2119 |
} |
| 2120 |
|
2120 |
|
| 2121 |
if (Attrs.hasFnAttr("aarch64_pstate_sm_enabled")) { |
2121 |
if (Attrs.hasFnAttr("aarch64_pstate_sm_enabled")) { |
| 2122 |
Check(!Attrs.hasFnAttr("aarch64_pstate_sm_compatible"), |
2122 |
Check(!Attrs.hasFnAttr("aarch64_pstate_sm_compatible"), |
| 2123 |
"Attributes 'aarch64_pstate_sm_enabled and " |
2123 |
"Attributes 'aarch64_pstate_sm_enabled and " |
| 2124 |
"aarch64_pstate_sm_compatible' are incompatible!", |
2124 |
"aarch64_pstate_sm_compatible' are incompatible!", |
| 2125 |
V); |
2125 |
V); |
| 2126 |
} |
2126 |
} |
| 2127 |
|
2127 |
|
| 2128 |
if (Attrs.hasFnAttr("aarch64_pstate_za_new")) { |
2128 |
if (Attrs.hasFnAttr("aarch64_pstate_za_new")) { |
| 2129 |
Check(!Attrs.hasFnAttr("aarch64_pstate_za_preserved"), |
2129 |
Check(!Attrs.hasFnAttr("aarch64_pstate_za_preserved"), |
| 2130 |
"Attributes 'aarch64_pstate_za_new and aarch64_pstate_za_preserved' " |
2130 |
"Attributes 'aarch64_pstate_za_new and aarch64_pstate_za_preserved' " |
| 2131 |
"are incompatible!", |
2131 |
"are incompatible!", |
| 2132 |
V); |
2132 |
V); |
| 2133 |
|
2133 |
|
| 2134 |
Check(!Attrs.hasFnAttr("aarch64_pstate_za_shared"), |
2134 |
Check(!Attrs.hasFnAttr("aarch64_pstate_za_shared"), |
| 2135 |
"Attributes 'aarch64_pstate_za_new and aarch64_pstate_za_shared' " |
2135 |
"Attributes 'aarch64_pstate_za_new and aarch64_pstate_za_shared' " |
| 2136 |
"are incompatible!", |
2136 |
"are incompatible!", |
| 2137 |
V); |
2137 |
V); |
| 2138 |
} |
2138 |
} |
| 2139 |
|
2139 |
|
| 2140 |
if (Attrs.hasFnAttr(Attribute::JumpTable)) { |
2140 |
if (Attrs.hasFnAttr(Attribute::JumpTable)) { |
| 2141 |
const GlobalValue *GV = cast(V); |
2141 |
const GlobalValue *GV = cast(V); |
| 2142 |
Check(GV->hasGlobalUnnamedAddr(), |
2142 |
Check(GV->hasGlobalUnnamedAddr(), |
| 2143 |
"Attribute 'jumptable' requires 'unnamed_addr'", V); |
2143 |
"Attribute 'jumptable' requires 'unnamed_addr'", V); |
| 2144 |
} |
2144 |
} |
| 2145 |
|
2145 |
|
| 2146 |
if (auto Args = Attrs.getFnAttrs().getAllocSizeArgs()) { |
2146 |
if (auto Args = Attrs.getFnAttrs().getAllocSizeArgs()) { |
| 2147 |
auto CheckParam = [&](StringRef Name, unsigned ParamNo) { |
2147 |
auto CheckParam = [&](StringRef Name, unsigned ParamNo) { |
| 2148 |
if (ParamNo >= FT->getNumParams()) { |
2148 |
if (ParamNo >= FT->getNumParams()) { |
| 2149 |
CheckFailed("'allocsize' " + Name + " argument is out of bounds", V); |
2149 |
CheckFailed("'allocsize' " + Name + " argument is out of bounds", V); |
| 2150 |
return false; |
2150 |
return false; |
| 2151 |
} |
2151 |
} |
| 2152 |
|
2152 |
|
| 2153 |
if (!FT->getParamType(ParamNo)->isIntegerTy()) { |
2153 |
if (!FT->getParamType(ParamNo)->isIntegerTy()) { |
| 2154 |
CheckFailed("'allocsize' " + Name + |
2154 |
CheckFailed("'allocsize' " + Name + |
| 2155 |
" argument must refer to an integer parameter", |
2155 |
" argument must refer to an integer parameter", |
| 2156 |
V); |
2156 |
V); |
| 2157 |
return false; |
2157 |
return false; |
| 2158 |
} |
2158 |
} |
| 2159 |
|
2159 |
|
| 2160 |
return true; |
2160 |
return true; |
| 2161 |
}; |
2161 |
}; |
| 2162 |
|
2162 |
|
| 2163 |
if (!CheckParam("element size", Args->first)) |
2163 |
if (!CheckParam("element size", Args->first)) |
| 2164 |
return; |
2164 |
return; |
| 2165 |
|
2165 |
|
| 2166 |
if (Args->second && !CheckParam("number of elements", *Args->second)) |
2166 |
if (Args->second && !CheckParam("number of elements", *Args->second)) |
| 2167 |
return; |
2167 |
return; |
| 2168 |
} |
2168 |
} |
| 2169 |
|
2169 |
|
| 2170 |
if (Attrs.hasFnAttr(Attribute::AllocKind)) { |
2170 |
if (Attrs.hasFnAttr(Attribute::AllocKind)) { |
| 2171 |
AllocFnKind K = Attrs.getAllocKind(); |
2171 |
AllocFnKind K = Attrs.getAllocKind(); |
| 2172 |
AllocFnKind Type = |
2172 |
AllocFnKind Type = |
| 2173 |
K & (AllocFnKind::Alloc | AllocFnKind::Realloc | AllocFnKind::Free); |
2173 |
K & (AllocFnKind::Alloc | AllocFnKind::Realloc | AllocFnKind::Free); |
| 2174 |
if (!is_contained( |
2174 |
if (!is_contained( |
| 2175 |
{AllocFnKind::Alloc, AllocFnKind::Realloc, AllocFnKind::Free}, |
2175 |
{AllocFnKind::Alloc, AllocFnKind::Realloc, AllocFnKind::Free}, |
| 2176 |
Type)) |
2176 |
Type)) |
| 2177 |
CheckFailed( |
2177 |
CheckFailed( |
| 2178 |
"'allockind()' requires exactly one of alloc, realloc, and free"); |
2178 |
"'allockind()' requires exactly one of alloc, realloc, and free"); |
| 2179 |
if ((Type == AllocFnKind::Free) && |
2179 |
if ((Type == AllocFnKind::Free) && |
| 2180 |
((K & (AllocFnKind::Uninitialized | AllocFnKind::Zeroed | |
2180 |
((K & (AllocFnKind::Uninitialized | AllocFnKind::Zeroed | |
| 2181 |
AllocFnKind::Aligned)) != AllocFnKind::Unknown)) |
2181 |
AllocFnKind::Aligned)) != AllocFnKind::Unknown)) |
| 2182 |
CheckFailed("'allockind(\"free\")' doesn't allow uninitialized, zeroed, " |
2182 |
CheckFailed("'allockind(\"free\")' doesn't allow uninitialized, zeroed, " |
| 2183 |
"or aligned modifiers."); |
2183 |
"or aligned modifiers."); |
| 2184 |
AllocFnKind ZeroedUninit = AllocFnKind::Uninitialized | AllocFnKind::Zeroed; |
2184 |
AllocFnKind ZeroedUninit = AllocFnKind::Uninitialized | AllocFnKind::Zeroed; |
| 2185 |
if ((K & ZeroedUninit) == ZeroedUninit) |
2185 |
if ((K & ZeroedUninit) == ZeroedUninit) |
| 2186 |
CheckFailed("'allockind()' can't be both zeroed and uninitialized"); |
2186 |
CheckFailed("'allockind()' can't be both zeroed and uninitialized"); |
| 2187 |
} |
2187 |
} |
| 2188 |
|
2188 |
|
| 2189 |
if (Attrs.hasFnAttr(Attribute::VScaleRange)) { |
2189 |
if (Attrs.hasFnAttr(Attribute::VScaleRange)) { |
| 2190 |
unsigned VScaleMin = Attrs.getFnAttrs().getVScaleRangeMin(); |
2190 |
unsigned VScaleMin = Attrs.getFnAttrs().getVScaleRangeMin(); |
| 2191 |
if (VScaleMin == 0) |
2191 |
if (VScaleMin == 0) |
| 2192 |
CheckFailed("'vscale_range' minimum must be greater than 0", V); |
2192 |
CheckFailed("'vscale_range' minimum must be greater than 0", V); |
| 2193 |
else if (!isPowerOf2_32(VScaleMin)) |
2193 |
else if (!isPowerOf2_32(VScaleMin)) |
| 2194 |
CheckFailed("'vscale_range' minimum must be power-of-two value", V); |
2194 |
CheckFailed("'vscale_range' minimum must be power-of-two value", V); |
| 2195 |
std::optional VScaleMax = Attrs.getFnAttrs().getVScaleRangeMax(); |
2195 |
std::optional VScaleMax = Attrs.getFnAttrs().getVScaleRangeMax(); |
| 2196 |
if (VScaleMax && VScaleMin > VScaleMax) |
2196 |
if (VScaleMax && VScaleMin > VScaleMax) |
| 2197 |
CheckFailed("'vscale_range' minimum cannot be greater than maximum", V); |
2197 |
CheckFailed("'vscale_range' minimum cannot be greater than maximum", V); |
| 2198 |
else if (VScaleMax && !isPowerOf2_32(*VScaleMax)) |
2198 |
else if (VScaleMax && !isPowerOf2_32(*VScaleMax)) |
| 2199 |
CheckFailed("'vscale_range' maximum must be power-of-two value", V); |
2199 |
CheckFailed("'vscale_range' maximum must be power-of-two value", V); |
| 2200 |
} |
2200 |
} |
| 2201 |
|
2201 |
|
| 2202 |
if (Attrs.hasFnAttr("frame-pointer")) { |
2202 |
if (Attrs.hasFnAttr("frame-pointer")) { |
| 2203 |
StringRef FP = Attrs.getFnAttr("frame-pointer").getValueAsString(); |
2203 |
StringRef FP = Attrs.getFnAttr("frame-pointer").getValueAsString(); |
| 2204 |
if (FP != "all" && FP != "non-leaf" && FP != "none") |
2204 |
if (FP != "all" && FP != "non-leaf" && FP != "none") |
| 2205 |
CheckFailed("invalid value for 'frame-pointer' attribute: " + FP, V); |
2205 |
CheckFailed("invalid value for 'frame-pointer' attribute: " + FP, V); |
| 2206 |
} |
2206 |
} |
| 2207 |
|
2207 |
|
| 2208 |
checkUnsignedBaseTenFuncAttr(Attrs, "patchable-function-prefix", V); |
2208 |
checkUnsignedBaseTenFuncAttr(Attrs, "patchable-function-prefix", V); |
| 2209 |
checkUnsignedBaseTenFuncAttr(Attrs, "patchable-function-entry", V); |
2209 |
checkUnsignedBaseTenFuncAttr(Attrs, "patchable-function-entry", V); |
| 2210 |
checkUnsignedBaseTenFuncAttr(Attrs, "warn-stack-size", V); |
2210 |
checkUnsignedBaseTenFuncAttr(Attrs, "warn-stack-size", V); |
| 2211 |
} |
2211 |
} |
| 2212 |
|
2212 |
|
| 2213 |
void Verifier::verifyFunctionMetadata( |
2213 |
void Verifier::verifyFunctionMetadata( |
| 2214 |
ArrayRef> MDs) { |
2214 |
ArrayRef> MDs) { |
| 2215 |
for (const auto &Pair : MDs) { |
2215 |
for (const auto &Pair : MDs) { |
| 2216 |
if (Pair.first == LLVMContext::MD_prof) { |
2216 |
if (Pair.first == LLVMContext::MD_prof) { |
| 2217 |
MDNode *MD = Pair.second; |
2217 |
MDNode *MD = Pair.second; |
| 2218 |
Check(MD->getNumOperands() >= 2, |
2218 |
Check(MD->getNumOperands() >= 2, |
| 2219 |
"!prof annotations should have no less than 2 operands", MD); |
2219 |
"!prof annotations should have no less than 2 operands", MD); |
| 2220 |
|
2220 |
|
| 2221 |
// Check first operand. |
2221 |
// Check first operand. |
| 2222 |
Check(MD->getOperand(0) != nullptr, "first operand should not be null", |
2222 |
Check(MD->getOperand(0) != nullptr, "first operand should not be null", |
| 2223 |
MD); |
2223 |
MD); |
| 2224 |
Check(isa(MD->getOperand(0)), |
2224 |
Check(isa(MD->getOperand(0)), |
| 2225 |
"expected string with name of the !prof annotation", MD); |
2225 |
"expected string with name of the !prof annotation", MD); |
| 2226 |
MDString *MDS = cast(MD->getOperand(0)); |
2226 |
MDString *MDS = cast(MD->getOperand(0)); |
| 2227 |
StringRef ProfName = MDS->getString(); |
2227 |
StringRef ProfName = MDS->getString(); |
| 2228 |
Check(ProfName.equals("function_entry_count") || |
2228 |
Check(ProfName.equals("function_entry_count") || |
| 2229 |
ProfName.equals("synthetic_function_entry_count"), |
2229 |
ProfName.equals("synthetic_function_entry_count"), |
| 2230 |
"first operand should be 'function_entry_count'" |
2230 |
"first operand should be 'function_entry_count'" |
| 2231 |
" or 'synthetic_function_entry_count'", |
2231 |
" or 'synthetic_function_entry_count'", |
| 2232 |
MD); |
2232 |
MD); |
| 2233 |
|
2233 |
|
| 2234 |
// Check second operand. |
2234 |
// Check second operand. |
| 2235 |
Check(MD->getOperand(1) != nullptr, "second operand should not be null", |
2235 |
Check(MD->getOperand(1) != nullptr, "second operand should not be null", |
| 2236 |
MD); |
2236 |
MD); |
| 2237 |
Check(isa(MD->getOperand(1)), |
2237 |
Check(isa(MD->getOperand(1)), |
| 2238 |
"expected integer argument to function_entry_count", MD); |
2238 |
"expected integer argument to function_entry_count", MD); |
| 2239 |
} else if (Pair.first == LLVMContext::MD_kcfi_type) { |
2239 |
} else if (Pair.first == LLVMContext::MD_kcfi_type) { |
| 2240 |
MDNode *MD = Pair.second; |
2240 |
MDNode *MD = Pair.second; |
| 2241 |
Check(MD->getNumOperands() == 1, |
2241 |
Check(MD->getNumOperands() == 1, |
| 2242 |
"!kcfi_type must have exactly one operand", MD); |
2242 |
"!kcfi_type must have exactly one operand", MD); |
| 2243 |
Check(MD->getOperand(0) != nullptr, "!kcfi_type operand must not be null", |
2243 |
Check(MD->getOperand(0) != nullptr, "!kcfi_type operand must not be null", |
| 2244 |
MD); |
2244 |
MD); |
| 2245 |
Check(isa(MD->getOperand(0)), |
2245 |
Check(isa(MD->getOperand(0)), |
| 2246 |
"expected a constant operand for !kcfi_type", MD); |
2246 |
"expected a constant operand for !kcfi_type", MD); |
| 2247 |
Constant *C = cast(MD->getOperand(0))->getValue(); |
2247 |
Constant *C = cast(MD->getOperand(0))->getValue(); |
| 2248 |
Check(isa(C), |
2248 |
Check(isa(C), |
| 2249 |
"expected a constant integer operand for !kcfi_type", MD); |
2249 |
"expected a constant integer operand for !kcfi_type", MD); |
| 2250 |
IntegerType *Type = cast(C)->getType(); |
2250 |
IntegerType *Type = cast(C)->getType(); |
| 2251 |
Check(Type->getBitWidth() == 32, |
2251 |
Check(Type->getBitWidth() == 32, |
| 2252 |
"expected a 32-bit integer constant operand for !kcfi_type", MD); |
2252 |
"expected a 32-bit integer constant operand for !kcfi_type", MD); |
| 2253 |
} |
2253 |
} |
| 2254 |
} |
2254 |
} |
| 2255 |
} |
2255 |
} |
| 2256 |
|
2256 |
|
| 2257 |
void Verifier::visitConstantExprsRecursively(const Constant *EntryC) { |
2257 |
void Verifier::visitConstantExprsRecursively(const Constant *EntryC) { |
| 2258 |
if (!ConstantExprVisited.insert(EntryC).second) |
2258 |
if (!ConstantExprVisited.insert(EntryC).second) |
| 2259 |
return; |
2259 |
return; |
| 2260 |
|
2260 |
|
| 2261 |
SmallVector Stack; |
2261 |
SmallVector Stack; |
| 2262 |
Stack.push_back(EntryC); |
2262 |
Stack.push_back(EntryC); |
| 2263 |
|
2263 |
|
| 2264 |
while (!Stack.empty()) { |
2264 |
while (!Stack.empty()) { |
| 2265 |
const Constant *C = Stack.pop_back_val(); |
2265 |
const Constant *C = Stack.pop_back_val(); |
| 2266 |
|
2266 |
|
| 2267 |
// Check this constant expression. |
2267 |
// Check this constant expression. |
| 2268 |
if (const auto *CE = dyn_cast(C)) |
2268 |
if (const auto *CE = dyn_cast(C)) |
| 2269 |
visitConstantExpr(CE); |
2269 |
visitConstantExpr(CE); |
| 2270 |
|
2270 |
|
| 2271 |
if (const auto *GV = dyn_cast(C)) { |
2271 |
if (const auto *GV = dyn_cast(C)) { |
| 2272 |
// Global Values get visited separately, but we do need to make sure |
2272 |
// Global Values get visited separately, but we do need to make sure |
| 2273 |
// that the global value is in the correct module |
2273 |
// that the global value is in the correct module |
| 2274 |
Check(GV->getParent() == &M, "Referencing global in another module!", |
2274 |
Check(GV->getParent() == &M, "Referencing global in another module!", |
| 2275 |
EntryC, &M, GV, GV->getParent()); |
2275 |
EntryC, &M, GV, GV->getParent()); |
| 2276 |
continue; |
2276 |
continue; |
| 2277 |
} |
2277 |
} |
| 2278 |
|
2278 |
|
| 2279 |
// Visit all sub-expressions. |
2279 |
// Visit all sub-expressions. |
| 2280 |
for (const Use &U : C->operands()) { |
2280 |
for (const Use &U : C->operands()) { |
| 2281 |
const auto *OpC = dyn_cast(U); |
2281 |
const auto *OpC = dyn_cast(U); |
| 2282 |
if (!OpC) |
2282 |
if (!OpC) |
| 2283 |
continue; |
2283 |
continue; |
| 2284 |
if (!ConstantExprVisited.insert(OpC).second) |
2284 |
if (!ConstantExprVisited.insert(OpC).second) |
| 2285 |
continue; |
2285 |
continue; |
| 2286 |
Stack.push_back(OpC); |
2286 |
Stack.push_back(OpC); |
| 2287 |
} |
2287 |
} |
| 2288 |
} |
2288 |
} |
| 2289 |
} |
2289 |
} |
| 2290 |
|
2290 |
|
| 2291 |
void Verifier::visitConstantExpr(const ConstantExpr *CE) { |
2291 |
void Verifier::visitConstantExpr(const ConstantExpr *CE) { |
| 2292 |
if (CE->getOpcode() == Instruction::BitCast) |
2292 |
if (CE->getOpcode() == Instruction::BitCast) |
| 2293 |
Check(CastInst::castIsValid(Instruction::BitCast, CE->getOperand(0), |
2293 |
Check(CastInst::castIsValid(Instruction::BitCast, CE->getOperand(0), |
| 2294 |
CE->getType()), |
2294 |
CE->getType()), |
| 2295 |
"Invalid bitcast", CE); |
2295 |
"Invalid bitcast", CE); |
| 2296 |
} |
2296 |
} |
| 2297 |
|
2297 |
|
| 2298 |
bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) { |
2298 |
bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) { |
| 2299 |
// There shouldn't be more attribute sets than there are parameters plus the |
2299 |
// There shouldn't be more attribute sets than there are parameters plus the |
| 2300 |
// function and return value. |
2300 |
// function and return value. |
| 2301 |
return Attrs.getNumAttrSets() <= Params + 2; |
2301 |
return Attrs.getNumAttrSets() <= Params + 2; |
| 2302 |
} |
2302 |
} |
| 2303 |
|
2303 |
|
| 2304 |
void Verifier::verifyInlineAsmCall(const CallBase &Call) { |
2304 |
void Verifier::verifyInlineAsmCall(const CallBase &Call) { |
| 2305 |
const InlineAsm *IA = cast(Call.getCalledOperand()); |
2305 |
const InlineAsm *IA = cast(Call.getCalledOperand()); |
| 2306 |
unsigned ArgNo = 0; |
2306 |
unsigned ArgNo = 0; |
| 2307 |
unsigned LabelNo = 0; |
2307 |
unsigned LabelNo = 0; |
| 2308 |
for (const InlineAsm::ConstraintInfo &CI : IA->ParseConstraints()) { |
2308 |
for (const InlineAsm::ConstraintInfo &CI : IA->ParseConstraints()) { |
| 2309 |
if (CI.Type == InlineAsm::isLabel) { |
2309 |
if (CI.Type == InlineAsm::isLabel) { |
| 2310 |
++LabelNo; |
2310 |
++LabelNo; |
| 2311 |
continue; |
2311 |
continue; |
| 2312 |
} |
2312 |
} |
| 2313 |
|
2313 |
|
| 2314 |
// Only deal with constraints that correspond to call arguments. |
2314 |
// Only deal with constraints that correspond to call arguments. |
| 2315 |
if (!CI.hasArg()) |
2315 |
if (!CI.hasArg()) |
| 2316 |
continue; |
2316 |
continue; |
| 2317 |
|
2317 |
|
| 2318 |
if (CI.isIndirect) { |
2318 |
if (CI.isIndirect) { |
| 2319 |
const Value *Arg = Call.getArgOperand(ArgNo); |
2319 |
const Value *Arg = Call.getArgOperand(ArgNo); |
| 2320 |
Check(Arg->getType()->isPointerTy(), |
2320 |
Check(Arg->getType()->isPointerTy(), |
| 2321 |
"Operand for indirect constraint must have pointer type", &Call); |
2321 |
"Operand for indirect constraint must have pointer type", &Call); |
| 2322 |
|
2322 |
|
| 2323 |
Check(Call.getParamElementType(ArgNo), |
2323 |
Check(Call.getParamElementType(ArgNo), |
| 2324 |
"Operand for indirect constraint must have elementtype attribute", |
2324 |
"Operand for indirect constraint must have elementtype attribute", |
| 2325 |
&Call); |
2325 |
&Call); |
| 2326 |
} else { |
2326 |
} else { |
| 2327 |
Check(!Call.paramHasAttr(ArgNo, Attribute::ElementType), |
2327 |
Check(!Call.paramHasAttr(ArgNo, Attribute::ElementType), |
| 2328 |
"Elementtype attribute can only be applied for indirect " |
2328 |
"Elementtype attribute can only be applied for indirect " |
| 2329 |
"constraints", |
2329 |
"constraints", |
| 2330 |
&Call); |
2330 |
&Call); |
| 2331 |
} |
2331 |
} |
| 2332 |
|
2332 |
|
| 2333 |
ArgNo++; |
2333 |
ArgNo++; |
| 2334 |
} |
2334 |
} |
| 2335 |
|
2335 |
|
| 2336 |
if (auto *CallBr = dyn_cast(&Call)) { |
2336 |
if (auto *CallBr = dyn_cast(&Call)) { |
| 2337 |
Check(LabelNo == CallBr->getNumIndirectDests(), |
2337 |
Check(LabelNo == CallBr->getNumIndirectDests(), |
| 2338 |
"Number of label constraints does not match number of callbr dests", |
2338 |
"Number of label constraints does not match number of callbr dests", |
| 2339 |
&Call); |
2339 |
&Call); |
| 2340 |
} else { |
2340 |
} else { |
| 2341 |
Check(LabelNo == 0, "Label constraints can only be used with callbr", |
2341 |
Check(LabelNo == 0, "Label constraints can only be used with callbr", |
| 2342 |
&Call); |
2342 |
&Call); |
| 2343 |
} |
2343 |
} |
| 2344 |
} |
2344 |
} |
| 2345 |
|
2345 |
|
| 2346 |
/// Verify that statepoint intrinsic is well formed. |
2346 |
/// Verify that statepoint intrinsic is well formed. |
| 2347 |
void Verifier::verifyStatepoint(const CallBase &Call) { |
2347 |
void Verifier::verifyStatepoint(const CallBase &Call) { |
| 2348 |
assert(Call.getCalledFunction() && |
2348 |
assert(Call.getCalledFunction() && |
| 2349 |
Call.getCalledFunction()->getIntrinsicID() == |
2349 |
Call.getCalledFunction()->getIntrinsicID() == |
| 2350 |
Intrinsic::experimental_gc_statepoint); |
2350 |
Intrinsic::experimental_gc_statepoint); |
| 2351 |
|
2351 |
|
| 2352 |
Check(!Call.doesNotAccessMemory() && !Call.onlyReadsMemory() && |
2352 |
Check(!Call.doesNotAccessMemory() && !Call.onlyReadsMemory() && |
| 2353 |
!Call.onlyAccessesArgMemory(), |
2353 |
!Call.onlyAccessesArgMemory(), |
| 2354 |
"gc.statepoint must read and write all memory to preserve " |
2354 |
"gc.statepoint must read and write all memory to preserve " |
| 2355 |
"reordering restrictions required by safepoint semantics", |
2355 |
"reordering restrictions required by safepoint semantics", |
| 2356 |
Call); |
2356 |
Call); |
| 2357 |
|
2357 |
|
| 2358 |
const int64_t NumPatchBytes = |
2358 |
const int64_t NumPatchBytes = |
| 2359 |
cast(Call.getArgOperand(1))->getSExtValue(); |
2359 |
cast(Call.getArgOperand(1))->getSExtValue(); |
| 2360 |
assert(isInt<32>(NumPatchBytes) && "NumPatchBytesV is an i32!"); |
2360 |
assert(isInt<32>(NumPatchBytes) && "NumPatchBytesV is an i32!"); |
| 2361 |
Check(NumPatchBytes >= 0, |
2361 |
Check(NumPatchBytes >= 0, |
| 2362 |
"gc.statepoint number of patchable bytes must be " |
2362 |
"gc.statepoint number of patchable bytes must be " |
| 2363 |
"positive", |
2363 |
"positive", |
| 2364 |
Call); |
2364 |
Call); |
| 2365 |
|
2365 |
|
| 2366 |
Type *TargetElemType = Call.getParamElementType(2); |
2366 |
Type *TargetElemType = Call.getParamElementType(2); |
| 2367 |
Check(TargetElemType, |
2367 |
Check(TargetElemType, |
| 2368 |
"gc.statepoint callee argument must have elementtype attribute", Call); |
2368 |
"gc.statepoint callee argument must have elementtype attribute", Call); |
| 2369 |
FunctionType *TargetFuncType = dyn_cast(TargetElemType); |
2369 |
FunctionType *TargetFuncType = dyn_cast(TargetElemType); |
| 2370 |
Check(TargetFuncType, |
2370 |
Check(TargetFuncType, |
| 2371 |
"gc.statepoint callee elementtype must be function type", Call); |
2371 |
"gc.statepoint callee elementtype must be function type", Call); |
| 2372 |
|
2372 |
|
| 2373 |
const int NumCallArgs = cast(Call.getArgOperand(3))->getZExtValue(); |
2373 |
const int NumCallArgs = cast(Call.getArgOperand(3))->getZExtValue(); |
| 2374 |
Check(NumCallArgs >= 0, |
2374 |
Check(NumCallArgs >= 0, |
| 2375 |
"gc.statepoint number of arguments to underlying call " |
2375 |
"gc.statepoint number of arguments to underlying call " |
| 2376 |
"must be positive", |
2376 |
"must be positive", |
| 2377 |
Call); |
2377 |
Call); |
| 2378 |
const int NumParams = (int)TargetFuncType->getNumParams(); |
2378 |
const int NumParams = (int)TargetFuncType->getNumParams(); |
| 2379 |
if (TargetFuncType->isVarArg()) { |
2379 |
if (TargetFuncType->isVarArg()) { |
| 2380 |
Check(NumCallArgs >= NumParams, |
2380 |
Check(NumCallArgs >= NumParams, |
| 2381 |
"gc.statepoint mismatch in number of vararg call args", Call); |
2381 |
"gc.statepoint mismatch in number of vararg call args", Call); |
| 2382 |
|
2382 |
|
| 2383 |
// TODO: Remove this limitation |
2383 |
// TODO: Remove this limitation |
| 2384 |
Check(TargetFuncType->getReturnType()->isVoidTy(), |
2384 |
Check(TargetFuncType->getReturnType()->isVoidTy(), |
| 2385 |
"gc.statepoint doesn't support wrapping non-void " |
2385 |
"gc.statepoint doesn't support wrapping non-void " |
| 2386 |
"vararg functions yet", |
2386 |
"vararg functions yet", |
| 2387 |
Call); |
2387 |
Call); |
| 2388 |
} else |
2388 |
} else |
| 2389 |
Check(NumCallArgs == NumParams, |
2389 |
Check(NumCallArgs == NumParams, |
| 2390 |
"gc.statepoint mismatch in number of call args", Call); |
2390 |
"gc.statepoint mismatch in number of call args", Call); |
| 2391 |
|
2391 |
|
| 2392 |
const uint64_t Flags |
2392 |
const uint64_t Flags |
| 2393 |
= cast(Call.getArgOperand(4))->getZExtValue(); |
2393 |
= cast(Call.getArgOperand(4))->getZExtValue(); |
| 2394 |
Check((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0, |
2394 |
Check((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0, |
| 2395 |
"unknown flag used in gc.statepoint flags argument", Call); |
2395 |
"unknown flag used in gc.statepoint flags argument", Call); |
| 2396 |
|
2396 |
|
| 2397 |
// Verify that the types of the call parameter arguments match |
2397 |
// Verify that the types of the call parameter arguments match |
| 2398 |
// the type of the wrapped callee. |
2398 |
// the type of the wrapped callee. |
| 2399 |
AttributeList Attrs = Call.getAttributes(); |
2399 |
AttributeList Attrs = Call.getAttributes(); |
| 2400 |
for (int i = 0; i < NumParams; i++) { |
2400 |
for (int i = 0; i < NumParams; i++) { |
| 2401 |
Type *ParamType = TargetFuncType->getParamType(i); |
2401 |
Type *ParamType = TargetFuncType->getParamType(i); |
| 2402 |
Type *ArgType = Call.getArgOperand(5 + i)->getType(); |
2402 |
Type *ArgType = Call.getArgOperand(5 + i)->getType(); |
| 2403 |
Check(ArgType == ParamType, |
2403 |
Check(ArgType == ParamType, |
| 2404 |
"gc.statepoint call argument does not match wrapped " |
2404 |
"gc.statepoint call argument does not match wrapped " |
| 2405 |
"function type", |
2405 |
"function type", |
| 2406 |
Call); |
2406 |
Call); |
| 2407 |
|
2407 |
|
| 2408 |
if (TargetFuncType->isVarArg()) { |
2408 |
if (TargetFuncType->isVarArg()) { |
| 2409 |
AttributeSet ArgAttrs = Attrs.getParamAttrs(5 + i); |
2409 |
AttributeSet ArgAttrs = Attrs.getParamAttrs(5 + i); |
| 2410 |
Check(!ArgAttrs.hasAttribute(Attribute::StructRet), |
2410 |
Check(!ArgAttrs.hasAttribute(Attribute::StructRet), |
| 2411 |
"Attribute 'sret' cannot be used for vararg call arguments!", Call); |
2411 |
"Attribute 'sret' cannot be used for vararg call arguments!", Call); |
| 2412 |
} |
2412 |
} |
| 2413 |
} |
2413 |
} |
| 2414 |
|
2414 |
|
| 2415 |
const int EndCallArgsInx = 4 + NumCallArgs; |
2415 |
const int EndCallArgsInx = 4 + NumCallArgs; |
| 2416 |
|
2416 |
|
| 2417 |
const Value *NumTransitionArgsV = Call.getArgOperand(EndCallArgsInx + 1); |
2417 |
const Value *NumTransitionArgsV = Call.getArgOperand(EndCallArgsInx + 1); |
| 2418 |
Check(isa(NumTransitionArgsV), |
2418 |
Check(isa(NumTransitionArgsV), |
| 2419 |
"gc.statepoint number of transition arguments " |
2419 |
"gc.statepoint number of transition arguments " |
| 2420 |
"must be constant integer", |
2420 |
"must be constant integer", |
| 2421 |
Call); |
2421 |
Call); |
| 2422 |
const int NumTransitionArgs = |
2422 |
const int NumTransitionArgs = |
| 2423 |
cast(NumTransitionArgsV)->getZExtValue(); |
2423 |
cast(NumTransitionArgsV)->getZExtValue(); |
| 2424 |
Check(NumTransitionArgs == 0, |
2424 |
Check(NumTransitionArgs == 0, |
| 2425 |
"gc.statepoint w/inline transition bundle is deprecated", Call); |
2425 |
"gc.statepoint w/inline transition bundle is deprecated", Call); |
| 2426 |
const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs; |
2426 |
const int EndTransitionArgsInx = EndCallArgsInx + 1 + NumTransitionArgs; |
| 2427 |
|
2427 |
|
| 2428 |
const Value *NumDeoptArgsV = Call.getArgOperand(EndTransitionArgsInx + 1); |
2428 |
const Value *NumDeoptArgsV = Call.getArgOperand(EndTransitionArgsInx + 1); |
| 2429 |
Check(isa(NumDeoptArgsV), |
2429 |
Check(isa(NumDeoptArgsV), |
| 2430 |
"gc.statepoint number of deoptimization arguments " |
2430 |
"gc.statepoint number of deoptimization arguments " |
| 2431 |
"must be constant integer", |
2431 |
"must be constant integer", |
| 2432 |
Call); |
2432 |
Call); |
| 2433 |
const int NumDeoptArgs = cast(NumDeoptArgsV)->getZExtValue(); |
2433 |
const int NumDeoptArgs = cast(NumDeoptArgsV)->getZExtValue(); |
| 2434 |
Check(NumDeoptArgs == 0, |
2434 |
Check(NumDeoptArgs == 0, |
| 2435 |
"gc.statepoint w/inline deopt operands is deprecated", Call); |
2435 |
"gc.statepoint w/inline deopt operands is deprecated", Call); |
| 2436 |
|
2436 |
|
| 2437 |
const int ExpectedNumArgs = 7 + NumCallArgs; |
2437 |
const int ExpectedNumArgs = 7 + NumCallArgs; |
| 2438 |
Check(ExpectedNumArgs == (int)Call.arg_size(), |
2438 |
Check(ExpectedNumArgs == (int)Call.arg_size(), |
| 2439 |
"gc.statepoint too many arguments", Call); |
2439 |
"gc.statepoint too many arguments", Call); |
| 2440 |
|
2440 |
|
| 2441 |
// Check that the only uses of this gc.statepoint are gc.result or |
2441 |
// Check that the only uses of this gc.statepoint are gc.result or |
| 2442 |
// gc.relocate calls which are tied to this statepoint and thus part |
2442 |
// gc.relocate calls which are tied to this statepoint and thus part |
| 2443 |
// of the same statepoint sequence |
2443 |
// of the same statepoint sequence |
| 2444 |
for (const User *U : Call.users()) { |
2444 |
for (const User *U : Call.users()) { |
| 2445 |
const CallInst *UserCall = dyn_cast(U); |
2445 |
const CallInst *UserCall = dyn_cast(U); |
| 2446 |
Check(UserCall, "illegal use of statepoint token", Call, U); |
2446 |
Check(UserCall, "illegal use of statepoint token", Call, U); |
| 2447 |
if (!UserCall) |
2447 |
if (!UserCall) |
| 2448 |
continue; |
2448 |
continue; |
| 2449 |
Check(isa(UserCall) || isa(UserCall), |
2449 |
Check(isa(UserCall) || isa(UserCall), |
| 2450 |
"gc.result or gc.relocate are the only value uses " |
2450 |
"gc.result or gc.relocate are the only value uses " |
| 2451 |
"of a gc.statepoint", |
2451 |
"of a gc.statepoint", |
| 2452 |
Call, U); |
2452 |
Call, U); |
| 2453 |
if (isa(UserCall)) { |
2453 |
if (isa(UserCall)) { |
| 2454 |
Check(UserCall->getArgOperand(0) == &Call, |
2454 |
Check(UserCall->getArgOperand(0) == &Call, |
| 2455 |
"gc.result connected to wrong gc.statepoint", Call, UserCall); |
2455 |
"gc.result connected to wrong gc.statepoint", Call, UserCall); |
| 2456 |
} else if (isa(Call)) { |
2456 |
} else if (isa(Call)) { |
| 2457 |
Check(UserCall->getArgOperand(0) == &Call, |
2457 |
Check(UserCall->getArgOperand(0) == &Call, |
| 2458 |
"gc.relocate connected to wrong gc.statepoint", Call, UserCall); |
2458 |
"gc.relocate connected to wrong gc.statepoint", Call, UserCall); |
| 2459 |
} |
2459 |
} |
| 2460 |
} |
2460 |
} |
| 2461 |
|
2461 |
|
| 2462 |
// Note: It is legal for a single derived pointer to be listed multiple |
2462 |
// Note: It is legal for a single derived pointer to be listed multiple |
| 2463 |
// times. It's non-optimal, but it is legal. It can also happen after |
2463 |
// times. It's non-optimal, but it is legal. It can also happen after |
| 2464 |
// insertion if we strip a bitcast away. |
2464 |
// insertion if we strip a bitcast away. |
| 2465 |
// Note: It is really tempting to check that each base is relocated and |
2465 |
// Note: It is really tempting to check that each base is relocated and |
| 2466 |
// that a derived pointer is never reused as a base pointer. This turns |
2466 |
// that a derived pointer is never reused as a base pointer. This turns |
| 2467 |
// out to be problematic since optimizations run after safepoint insertion |
2467 |
// out to be problematic since optimizations run after safepoint insertion |
| 2468 |
// can recognize equality properties that the insertion logic doesn't know |
2468 |
// can recognize equality properties that the insertion logic doesn't know |
| 2469 |
// about. See example statepoint.ll in the verifier subdirectory |
2469 |
// about. See example statepoint.ll in the verifier subdirectory |
| 2470 |
} |
2470 |
} |
| 2471 |
|
2471 |
|
| 2472 |
void Verifier::verifyFrameRecoverIndices() { |
2472 |
void Verifier::verifyFrameRecoverIndices() { |
| 2473 |
for (auto &Counts : FrameEscapeInfo) { |
2473 |
for (auto &Counts : FrameEscapeInfo) { |
| 2474 |
Function *F = Counts.first; |
2474 |
Function *F = Counts.first; |
| 2475 |
unsigned EscapedObjectCount = Counts.second.first; |
2475 |
unsigned EscapedObjectCount = Counts.second.first; |
| 2476 |
unsigned MaxRecoveredIndex = Counts.second.second; |
2476 |
unsigned MaxRecoveredIndex = Counts.second.second; |
| 2477 |
Check(MaxRecoveredIndex <= EscapedObjectCount, |
2477 |
Check(MaxRecoveredIndex <= EscapedObjectCount, |
| 2478 |
"all indices passed to llvm.localrecover must be less than the " |
2478 |
"all indices passed to llvm.localrecover must be less than the " |
| 2479 |
"number of arguments passed to llvm.localescape in the parent " |
2479 |
"number of arguments passed to llvm.localescape in the parent " |
| 2480 |
"function", |
2480 |
"function", |
| 2481 |
F); |
2481 |
F); |
| 2482 |
} |
2482 |
} |
| 2483 |
} |
2483 |
} |
| 2484 |
|
2484 |
|
| 2485 |
static Instruction *getSuccPad(Instruction *Terminator) { |
2485 |
static Instruction *getSuccPad(Instruction *Terminator) { |
| 2486 |
BasicBlock *UnwindDest; |
2486 |
BasicBlock *UnwindDest; |
| 2487 |
if (auto *II = dyn_cast(Terminator)) |
2487 |
if (auto *II = dyn_cast(Terminator)) |
| 2488 |
UnwindDest = II->getUnwindDest(); |
2488 |
UnwindDest = II->getUnwindDest(); |
| 2489 |
else if (auto *CSI = dyn_cast(Terminator)) |
2489 |
else if (auto *CSI = dyn_cast(Terminator)) |
| 2490 |
UnwindDest = CSI->getUnwindDest(); |
2490 |
UnwindDest = CSI->getUnwindDest(); |
| 2491 |
else |
2491 |
else |
| 2492 |
UnwindDest = cast(Terminator)->getUnwindDest(); |
2492 |
UnwindDest = cast(Terminator)->getUnwindDest(); |
| 2493 |
return UnwindDest->getFirstNonPHI(); |
2493 |
return UnwindDest->getFirstNonPHI(); |
| 2494 |
} |
2494 |
} |
| 2495 |
|
2495 |
|
| 2496 |
void Verifier::verifySiblingFuncletUnwinds() { |
2496 |
void Verifier::verifySiblingFuncletUnwinds() { |
| 2497 |
SmallPtrSet Visited; |
2497 |
SmallPtrSet Visited; |
| 2498 |
SmallPtrSet Active; |
2498 |
SmallPtrSet Active; |
| 2499 |
for (const auto &Pair : SiblingFuncletInfo) { |
2499 |
for (const auto &Pair : SiblingFuncletInfo) { |
| 2500 |
Instruction *PredPad = Pair.first; |
2500 |
Instruction *PredPad = Pair.first; |
| 2501 |
if (Visited.count(PredPad)) |
2501 |
if (Visited.count(PredPad)) |
| 2502 |
continue; |
2502 |
continue; |
| 2503 |
Active.insert(PredPad); |
2503 |
Active.insert(PredPad); |
| 2504 |
Instruction *Terminator = Pair.second; |
2504 |
Instruction *Terminator = Pair.second; |
| 2505 |
do { |
2505 |
do { |
| 2506 |
Instruction *SuccPad = getSuccPad(Terminator); |
2506 |
Instruction *SuccPad = getSuccPad(Terminator); |
| 2507 |
if (Active.count(SuccPad)) { |
2507 |
if (Active.count(SuccPad)) { |
| 2508 |
// Found a cycle; report error |
2508 |
// Found a cycle; report error |
| 2509 |
Instruction *CyclePad = SuccPad; |
2509 |
Instruction *CyclePad = SuccPad; |
| 2510 |
SmallVector CycleNodes; |
2510 |
SmallVector CycleNodes; |
| 2511 |
do { |
2511 |
do { |
| 2512 |
CycleNodes.push_back(CyclePad); |
2512 |
CycleNodes.push_back(CyclePad); |
| 2513 |
Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad]; |
2513 |
Instruction *CycleTerminator = SiblingFuncletInfo[CyclePad]; |
| 2514 |
if (CycleTerminator != CyclePad) |
2514 |
if (CycleTerminator != CyclePad) |
| 2515 |
CycleNodes.push_back(CycleTerminator); |
2515 |
CycleNodes.push_back(CycleTerminator); |
| 2516 |
CyclePad = getSuccPad(CycleTerminator); |
2516 |
CyclePad = getSuccPad(CycleTerminator); |
| 2517 |
} while (CyclePad != SuccPad); |
2517 |
} while (CyclePad != SuccPad); |
| 2518 |
Check(false, "EH pads can't handle each other's exceptions", |
2518 |
Check(false, "EH pads can't handle each other's exceptions", |
| 2519 |
ArrayRef(CycleNodes)); |
2519 |
ArrayRef(CycleNodes)); |
| 2520 |
} |
2520 |
} |
| 2521 |
// Don't re-walk a node we've already checked |
2521 |
// Don't re-walk a node we've already checked |
| 2522 |
if (!Visited.insert(SuccPad).second) |
2522 |
if (!Visited.insert(SuccPad).second) |
| 2523 |
break; |
2523 |
break; |
| 2524 |
// Walk to this successor if it has a map entry. |
2524 |
// Walk to this successor if it has a map entry. |
| 2525 |
PredPad = SuccPad; |
2525 |
PredPad = SuccPad; |
| 2526 |
auto TermI = SiblingFuncletInfo.find(PredPad); |
2526 |
auto TermI = SiblingFuncletInfo.find(PredPad); |
| 2527 |
if (TermI == SiblingFuncletInfo.end()) |
2527 |
if (TermI == SiblingFuncletInfo.end()) |
| 2528 |
break; |
2528 |
break; |
| 2529 |
Terminator = TermI->second; |
2529 |
Terminator = TermI->second; |
| 2530 |
Active.insert(PredPad); |
2530 |
Active.insert(PredPad); |
| 2531 |
} while (true); |
2531 |
} while (true); |
| 2532 |
// Each node only has one successor, so we've walked all the active |
2532 |
// Each node only has one successor, so we've walked all the active |
| 2533 |
// nodes' successors. |
2533 |
// nodes' successors. |
| 2534 |
Active.clear(); |
2534 |
Active.clear(); |
| 2535 |
} |
2535 |
} |
| 2536 |
} |
2536 |
} |
| 2537 |
|
2537 |
|
| 2538 |
void Verifier::verifyConvergenceControl(Function &F) { |
2538 |
void Verifier::verifyConvergenceControl(Function &F) { |
| 2539 |
DenseMap> LiveTokenMap; |
2539 |
DenseMap> LiveTokenMap; |
| 2540 |
DenseMap CycleHearts; |
2540 |
DenseMap CycleHearts; |
| 2541 |
|
2541 |
|
| 2542 |
// Just like the DominatorTree, compute the CycleInfo locally so that we |
2542 |
// Just like the DominatorTree, compute the CycleInfo locally so that we |
| 2543 |
// can run the verifier outside of a pass manager and we don't rely on |
2543 |
// can run the verifier outside of a pass manager and we don't rely on |
| 2544 |
// potentially out-dated analysis results. |
2544 |
// potentially out-dated analysis results. |
| 2545 |
CycleInfo CI; |
2545 |
CycleInfo CI; |
| 2546 |
CI.compute(F); |
2546 |
CI.compute(F); |
| 2547 |
|
2547 |
|
| 2548 |
auto checkBundle = [&](OperandBundleUse &Bundle, CallBase *CB, |
2548 |
auto checkBundle = [&](OperandBundleUse &Bundle, CallBase *CB, |
| 2549 |
SmallVectorImpl &LiveTokens) { |
2549 |
SmallVectorImpl &LiveTokens) { |
| 2550 |
Check(Bundle.Inputs.size() == 1 && Bundle.Inputs[0]->getType()->isTokenTy(), |
2550 |
Check(Bundle.Inputs.size() == 1 && Bundle.Inputs[0]->getType()->isTokenTy(), |
| 2551 |
"The 'convergencectrl' bundle requires exactly one token use.", CB); |
2551 |
"The 'convergencectrl' bundle requires exactly one token use.", CB); |
| 2552 |
|
2552 |
|
| 2553 |
Value *Token = Bundle.Inputs[0].get(); |
2553 |
Value *Token = Bundle.Inputs[0].get(); |
| 2554 |
auto *Def = dyn_cast(Token); |
2554 |
auto *Def = dyn_cast(Token); |
| 2555 |
Check(Def != nullptr, |
2555 |
Check(Def != nullptr, |
| 2556 |
"Convergence control tokens can only be produced by call " |
2556 |
"Convergence control tokens can only be produced by call " |
| 2557 |
"instructions.", |
2557 |
"instructions.", |
| 2558 |
Token); |
2558 |
Token); |
| 2559 |
|
2559 |
|
| 2560 |
Check(llvm::is_contained(LiveTokens, Token), |
2560 |
Check(llvm::is_contained(LiveTokens, Token), |
| 2561 |
"Convergence region is not well-nested.", Token, CB); |
2561 |
"Convergence region is not well-nested.", Token, CB); |
| 2562 |
|
2562 |
|
| 2563 |
while (LiveTokens.back() != Token) |
2563 |
while (LiveTokens.back() != Token) |
| 2564 |
LiveTokens.pop_back(); |
2564 |
LiveTokens.pop_back(); |
| 2565 |
|
2565 |
|
| 2566 |
// Check static rules about cycles. |
2566 |
// Check static rules about cycles. |
| 2567 |
auto *BB = CB->getParent(); |
2567 |
auto *BB = CB->getParent(); |
| 2568 |
auto *BBCycle = CI.getCycle(BB); |
2568 |
auto *BBCycle = CI.getCycle(BB); |
| 2569 |
if (!BBCycle) |
2569 |
if (!BBCycle) |
| 2570 |
return; |
2570 |
return; |
| 2571 |
|
2571 |
|
| 2572 |
BasicBlock *DefBB = Def->getParent(); |
2572 |
BasicBlock *DefBB = Def->getParent(); |
| 2573 |
if (DefBB == BB || BBCycle->contains(DefBB)) { |
2573 |
if (DefBB == BB || BBCycle->contains(DefBB)) { |
| 2574 |
// degenerate occurrence of a loop intrinsic |
2574 |
// degenerate occurrence of a loop intrinsic |
| 2575 |
return; |
2575 |
return; |
| 2576 |
} |
2576 |
} |
| 2577 |
|
2577 |
|
| 2578 |
auto *II = dyn_cast(CB); |
2578 |
auto *II = dyn_cast(CB); |
| 2579 |
Check(II && |
2579 |
Check(II && |
| 2580 |
II->getIntrinsicID() == Intrinsic::experimental_convergence_loop, |
2580 |
II->getIntrinsicID() == Intrinsic::experimental_convergence_loop, |
| 2581 |
"Convergence token used by an instruction other than " |
2581 |
"Convergence token used by an instruction other than " |
| 2582 |
"llvm.experimental.convergence.loop in a cycle that does " |
2582 |
"llvm.experimental.convergence.loop in a cycle that does " |
| 2583 |
"not contain the token's definition.", |
2583 |
"not contain the token's definition.", |
| 2584 |
CB, CI.print(BBCycle)); |
2584 |
CB, CI.print(BBCycle)); |
| 2585 |
|
2585 |
|
| 2586 |
while (true) { |
2586 |
while (true) { |
| 2587 |
auto *Parent = BBCycle->getParentCycle(); |
2587 |
auto *Parent = BBCycle->getParentCycle(); |
| 2588 |
if (!Parent || Parent->contains(DefBB)) |
2588 |
if (!Parent || Parent->contains(DefBB)) |
| 2589 |
break; |
2589 |
break; |
| 2590 |
BBCycle = Parent; |
2590 |
BBCycle = Parent; |
| 2591 |
}; |
2591 |
}; |
| 2592 |
|
2592 |
|
| 2593 |
Check(BBCycle->isReducible() && BB == BBCycle->getHeader(), |
2593 |
Check(BBCycle->isReducible() && BB == BBCycle->getHeader(), |
| 2594 |
"Cycle heart must dominate all blocks in the cycle.", CB, BB, |
2594 |
"Cycle heart must dominate all blocks in the cycle.", CB, BB, |
| 2595 |
CI.print(BBCycle)); |
2595 |
CI.print(BBCycle)); |
| 2596 |
Check(!CycleHearts.count(BBCycle), |
2596 |
Check(!CycleHearts.count(BBCycle), |
| 2597 |
"Two static convergence token uses in a cycle that does " |
2597 |
"Two static convergence token uses in a cycle that does " |
| 2598 |
"not contain either token's definition.", |
2598 |
"not contain either token's definition.", |
| 2599 |
CB, CycleHearts[BBCycle], CI.print(BBCycle)); |
2599 |
CB, CycleHearts[BBCycle], CI.print(BBCycle)); |
| 2600 |
CycleHearts[BBCycle] = CB; |
2600 |
CycleHearts[BBCycle] = CB; |
| 2601 |
}; |
2601 |
}; |
| 2602 |
|
2602 |
|
| 2603 |
ReversePostOrderTraversal RPOT(&F); |
2603 |
ReversePostOrderTraversal RPOT(&F); |
| 2604 |
SmallVector LiveTokens; |
2604 |
SmallVector LiveTokens; |
| 2605 |
for (BasicBlock *BB : RPOT) { |
2605 |
for (BasicBlock *BB : RPOT) { |
| 2606 |
LiveTokens.clear(); |
2606 |
LiveTokens.clear(); |
| 2607 |
auto LTIt = LiveTokenMap.find(BB); |
2607 |
auto LTIt = LiveTokenMap.find(BB); |
| 2608 |
if (LTIt != LiveTokenMap.end()) { |
2608 |
if (LTIt != LiveTokenMap.end()) { |
| 2609 |
LiveTokens = std::move(LTIt->second); |
2609 |
LiveTokens = std::move(LTIt->second); |
| 2610 |
LiveTokenMap.erase(LTIt); |
2610 |
LiveTokenMap.erase(LTIt); |
| 2611 |
} |
2611 |
} |
| 2612 |
|
2612 |
|
| 2613 |
for (Instruction &I : *BB) { |
2613 |
for (Instruction &I : *BB) { |
| 2614 |
CallBase *CB = dyn_cast(&I); |
2614 |
CallBase *CB = dyn_cast(&I); |
| 2615 |
if (!CB) |
2615 |
if (!CB) |
| 2616 |
continue; |
2616 |
continue; |
| 2617 |
|
2617 |
|
| 2618 |
auto Bundle = CB->getOperandBundle(LLVMContext::OB_convergencectrl); |
2618 |
auto Bundle = CB->getOperandBundle(LLVMContext::OB_convergencectrl); |
| 2619 |
if (Bundle) |
2619 |
if (Bundle) |
| 2620 |
checkBundle(*Bundle, CB, LiveTokens); |
2620 |
checkBundle(*Bundle, CB, LiveTokens); |
| 2621 |
|
2621 |
|
| 2622 |
if (CB->getType()->isTokenTy()) |
2622 |
if (CB->getType()->isTokenTy()) |
| 2623 |
LiveTokens.push_back(CB); |
2623 |
LiveTokens.push_back(CB); |
| 2624 |
} |
2624 |
} |
| 2625 |
|
2625 |
|
| 2626 |
// Propagate token liveness |
2626 |
// Propagate token liveness |
| 2627 |
for (BasicBlock *Succ : successors(BB)) { |
2627 |
for (BasicBlock *Succ : successors(BB)) { |
| 2628 |
DomTreeNode *SuccNode = DT.getNode(Succ); |
2628 |
DomTreeNode *SuccNode = DT.getNode(Succ); |
| 2629 |
LTIt = LiveTokenMap.find(Succ); |
2629 |
LTIt = LiveTokenMap.find(Succ); |
| 2630 |
if (LTIt == LiveTokenMap.end()) { |
2630 |
if (LTIt == LiveTokenMap.end()) { |
| 2631 |
// We're the first predecessor: all tokens which dominate the |
2631 |
// We're the first predecessor: all tokens which dominate the |
| 2632 |
// successor are live for now. |
2632 |
// successor are live for now. |
| 2633 |
LTIt = LiveTokenMap.try_emplace(Succ).first; |
2633 |
LTIt = LiveTokenMap.try_emplace(Succ).first; |
| 2634 |
for (CallBase *LiveToken : LiveTokens) { |
2634 |
for (CallBase *LiveToken : LiveTokens) { |
| 2635 |
if (!DT.dominates(DT.getNode(LiveToken->getParent()), SuccNode)) |
2635 |
if (!DT.dominates(DT.getNode(LiveToken->getParent()), SuccNode)) |
| 2636 |
break; |
2636 |
break; |
| 2637 |
LTIt->second.push_back(LiveToken); |
2637 |
LTIt->second.push_back(LiveToken); |
| 2638 |
} |
2638 |
} |
| 2639 |
} else { |
2639 |
} else { |
| 2640 |
// Compute the intersection of live tokens. |
2640 |
// Compute the intersection of live tokens. |
| 2641 |
auto It = llvm::partition(LTIt->second, [&LiveTokens](CallBase *Token) { |
2641 |
auto It = llvm::partition(LTIt->second, [&LiveTokens](CallBase *Token) { |
| 2642 |
return llvm::is_contained(LiveTokens, Token); |
2642 |
return llvm::is_contained(LiveTokens, Token); |
| 2643 |
}); |
2643 |
}); |
| 2644 |
LTIt->second.erase(It, LTIt->second.end()); |
2644 |
LTIt->second.erase(It, LTIt->second.end()); |
| 2645 |
} |
2645 |
} |
| 2646 |
} |
2646 |
} |
| 2647 |
} |
2647 |
} |
| 2648 |
} |
2648 |
} |
| 2649 |
|
2649 |
|
| 2650 |
// visitFunction - Verify that a function is ok. |
2650 |
// visitFunction - Verify that a function is ok. |
| 2651 |
// |
2651 |
// |
| 2652 |
void Verifier::visitFunction(const Function &F) { |
2652 |
void Verifier::visitFunction(const Function &F) { |
| 2653 |
visitGlobalValue(F); |
2653 |
visitGlobalValue(F); |
| 2654 |
|
2654 |
|
| 2655 |
// Check function arguments. |
2655 |
// Check function arguments. |
| 2656 |
FunctionType *FT = F.getFunctionType(); |
2656 |
FunctionType *FT = F.getFunctionType(); |
| 2657 |
unsigned NumArgs = F.arg_size(); |
2657 |
unsigned NumArgs = F.arg_size(); |
| 2658 |
|
2658 |
|
| 2659 |
Check(&Context == &F.getContext(), |
2659 |
Check(&Context == &F.getContext(), |
| 2660 |
"Function context does not match Module context!", &F); |
2660 |
"Function context does not match Module context!", &F); |
| 2661 |
|
2661 |
|
| 2662 |
Check(!F.hasCommonLinkage(), "Functions may not have common linkage", &F); |
2662 |
Check(!F.hasCommonLinkage(), "Functions may not have common linkage", &F); |
| 2663 |
Check(FT->getNumParams() == NumArgs, |
2663 |
Check(FT->getNumParams() == NumArgs, |
| 2664 |
"# formal arguments must match # of arguments for function type!", &F, |
2664 |
"# formal arguments must match # of arguments for function type!", &F, |
| 2665 |
FT); |
2665 |
FT); |
| 2666 |
Check(F.getReturnType()->isFirstClassType() || |
2666 |
Check(F.getReturnType()->isFirstClassType() || |
| 2667 |
F.getReturnType()->isVoidTy() || F.getReturnType()->isStructTy(), |
2667 |
F.getReturnType()->isVoidTy() || F.getReturnType()->isStructTy(), |
| 2668 |
"Functions cannot return aggregate values!", &F); |
2668 |
"Functions cannot return aggregate values!", &F); |
| 2669 |
|
2669 |
|
| 2670 |
Check(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(), |
2670 |
Check(!F.hasStructRetAttr() || F.getReturnType()->isVoidTy(), |
| 2671 |
"Invalid struct return type!", &F); |
2671 |
"Invalid struct return type!", &F); |
| 2672 |
|
2672 |
|
| 2673 |
AttributeList Attrs = F.getAttributes(); |
2673 |
AttributeList Attrs = F.getAttributes(); |
| 2674 |
|
2674 |
|
| 2675 |
Check(verifyAttributeCount(Attrs, FT->getNumParams()), |
2675 |
Check(verifyAttributeCount(Attrs, FT->getNumParams()), |
| 2676 |
"Attribute after last parameter!", &F); |
2676 |
"Attribute after last parameter!", &F); |
| 2677 |
|
2677 |
|
| 2678 |
bool IsIntrinsic = F.isIntrinsic(); |
2678 |
bool IsIntrinsic = F.isIntrinsic(); |
| 2679 |
|
2679 |
|
| 2680 |
// Check function attributes. |
2680 |
// Check function attributes. |
| 2681 |
verifyFunctionAttrs(FT, Attrs, &F, IsIntrinsic, /* IsInlineAsm */ false); |
2681 |
verifyFunctionAttrs(FT, Attrs, &F, IsIntrinsic, /* IsInlineAsm */ false); |
| 2682 |
|
2682 |
|
| 2683 |
// On function declarations/definitions, we do not support the builtin |
2683 |
// On function declarations/definitions, we do not support the builtin |
| 2684 |
// attribute. We do not check this in VerifyFunctionAttrs since that is |
2684 |
// attribute. We do not check this in VerifyFunctionAttrs since that is |
| 2685 |
// checking for Attributes that can/can not ever be on functions. |
2685 |
// checking for Attributes that can/can not ever be on functions. |
| 2686 |
Check(!Attrs.hasFnAttr(Attribute::Builtin), |
2686 |
Check(!Attrs.hasFnAttr(Attribute::Builtin), |
| 2687 |
"Attribute 'builtin' can only be applied to a callsite.", &F); |
2687 |
"Attribute 'builtin' can only be applied to a callsite.", &F); |
| 2688 |
|
2688 |
|
| 2689 |
Check(!Attrs.hasAttrSomewhere(Attribute::ElementType), |
2689 |
Check(!Attrs.hasAttrSomewhere(Attribute::ElementType), |
| 2690 |
"Attribute 'elementtype' can only be applied to a callsite.", &F); |
2690 |
"Attribute 'elementtype' can only be applied to a callsite.", &F); |
| 2691 |
|
2691 |
|
| 2692 |
// Check that this function meets the restrictions on this calling convention. |
2692 |
// Check that this function meets the restrictions on this calling convention. |
| 2693 |
// Sometimes varargs is used for perfectly forwarding thunks, so some of these |
2693 |
// Sometimes varargs is used for perfectly forwarding thunks, so some of these |
| 2694 |
// restrictions can be lifted. |
2694 |
// restrictions can be lifted. |
| 2695 |
switch (F.getCallingConv()) { |
2695 |
switch (F.getCallingConv()) { |
| 2696 |
default: |
2696 |
default: |
| 2697 |
case CallingConv::C: |
2697 |
case CallingConv::C: |
| 2698 |
break; |
2698 |
break; |
| 2699 |
case CallingConv::X86_INTR: { |
2699 |
case CallingConv::X86_INTR: { |
| 2700 |
Check(F.arg_empty() || Attrs.hasParamAttr(0, Attribute::ByVal), |
2700 |
Check(F.arg_empty() || Attrs.hasParamAttr(0, Attribute::ByVal), |
| 2701 |
"Calling convention parameter requires byval", &F); |
2701 |
"Calling convention parameter requires byval", &F); |
| 2702 |
break; |
2702 |
break; |
| 2703 |
} |
2703 |
} |
| 2704 |
case CallingConv::AMDGPU_KERNEL: |
2704 |
case CallingConv::AMDGPU_KERNEL: |
| 2705 |
case CallingConv::SPIR_KERNEL: |
2705 |
case CallingConv::SPIR_KERNEL: |
| 2706 |
case CallingConv::AMDGPU_CS_Chain: |
2706 |
case CallingConv::AMDGPU_CS_Chain: |
| 2707 |
case CallingConv::AMDGPU_CS_ChainPreserve: |
2707 |
case CallingConv::AMDGPU_CS_ChainPreserve: |
| 2708 |
Check(F.getReturnType()->isVoidTy(), |
2708 |
Check(F.getReturnType()->isVoidTy(), |
| 2709 |
"Calling convention requires void return type", &F); |
2709 |
"Calling convention requires void return type", &F); |
| 2710 |
[[fallthrough]]; |
2710 |
[[fallthrough]]; |
| 2711 |
case CallingConv::AMDGPU_VS: |
2711 |
case CallingConv::AMDGPU_VS: |
| 2712 |
case CallingConv::AMDGPU_HS: |
2712 |
case CallingConv::AMDGPU_HS: |
| 2713 |
case CallingConv::AMDGPU_GS: |
2713 |
case CallingConv::AMDGPU_GS: |
| 2714 |
case CallingConv::AMDGPU_PS: |
2714 |
case CallingConv::AMDGPU_PS: |
| 2715 |
case CallingConv::AMDGPU_CS: |
2715 |
case CallingConv::AMDGPU_CS: |
| 2716 |
Check(!F.hasStructRetAttr(), "Calling convention does not allow sret", &F); |
2716 |
Check(!F.hasStructRetAttr(), "Calling convention does not allow sret", &F); |
| 2717 |
if (F.getCallingConv() != CallingConv::SPIR_KERNEL) { |
2717 |
if (F.getCallingConv() != CallingConv::SPIR_KERNEL) { |
| 2718 |
const unsigned StackAS = DL.getAllocaAddrSpace(); |
2718 |
const unsigned StackAS = DL.getAllocaAddrSpace(); |
| 2719 |
unsigned i = 0; |
2719 |
unsigned i = 0; |
| 2720 |
for (const Argument &Arg : F.args()) { |
2720 |
for (const Argument &Arg : F.args()) { |
| 2721 |
Check(!Attrs.hasParamAttr(i, Attribute::ByVal), |
2721 |
Check(!Attrs.hasParamAttr(i, Attribute::ByVal), |
| 2722 |
"Calling convention disallows byval", &F); |
2722 |
"Calling convention disallows byval", &F); |
| 2723 |
Check(!Attrs.hasParamAttr(i, Attribute::Preallocated), |
2723 |
Check(!Attrs.hasParamAttr(i, Attribute::Preallocated), |
| 2724 |
"Calling convention disallows preallocated", &F); |
2724 |
"Calling convention disallows preallocated", &F); |
| 2725 |
Check(!Attrs.hasParamAttr(i, Attribute::InAlloca), |
2725 |
Check(!Attrs.hasParamAttr(i, Attribute::InAlloca), |
| 2726 |
"Calling convention disallows inalloca", &F); |
2726 |
"Calling convention disallows inalloca", &F); |
| 2727 |
|
2727 |
|
| 2728 |
if (Attrs.hasParamAttr(i, Attribute::ByRef)) { |
2728 |
if (Attrs.hasParamAttr(i, Attribute::ByRef)) { |
| 2729 |
// FIXME: Should also disallow LDS and GDS, but we don't have the enum |
2729 |
// FIXME: Should also disallow LDS and GDS, but we don't have the enum |
| 2730 |
// value here. |
2730 |
// value here. |
| 2731 |
Check(Arg.getType()->getPointerAddressSpace() != StackAS, |
2731 |
Check(Arg.getType()->getPointerAddressSpace() != StackAS, |
| 2732 |
"Calling convention disallows stack byref", &F); |
2732 |
"Calling convention disallows stack byref", &F); |
| 2733 |
} |
2733 |
} |
| 2734 |
|
2734 |
|
| 2735 |
++i; |
2735 |
++i; |
| 2736 |
} |
2736 |
} |
| 2737 |
} |
2737 |
} |
| 2738 |
|
2738 |
|
| 2739 |
[[fallthrough]]; |
2739 |
[[fallthrough]]; |
| 2740 |
case CallingConv::Fast: |
2740 |
case CallingConv::Fast: |
| 2741 |
case CallingConv::Cold: |
2741 |
case CallingConv::Cold: |
| 2742 |
case CallingConv::Intel_OCL_BI: |
2742 |
case CallingConv::Intel_OCL_BI: |
| 2743 |
case CallingConv::PTX_Kernel: |
2743 |
case CallingConv::PTX_Kernel: |
| 2744 |
case CallingConv::PTX_Device: |
2744 |
case CallingConv::PTX_Device: |
| 2745 |
Check(!F.isVarArg(), |
2745 |
Check(!F.isVarArg(), |
| 2746 |
"Calling convention does not support varargs or " |
2746 |
"Calling convention does not support varargs or " |
| 2747 |
"perfect forwarding!", |
2747 |
"perfect forwarding!", |
| 2748 |
&F); |
2748 |
&F); |
| 2749 |
break; |
2749 |
break; |
| 2750 |
} |
2750 |
} |
| 2751 |
|
2751 |
|
| 2752 |
// Check that the argument values match the function type for this function... |
2752 |
// Check that the argument values match the function type for this function... |
| 2753 |
unsigned i = 0; |
2753 |
unsigned i = 0; |
| 2754 |
for (const Argument &Arg : F.args()) { |
2754 |
for (const Argument &Arg : F.args()) { |
| 2755 |
Check(Arg.getType() == FT->getParamType(i), |
2755 |
Check(Arg.getType() == FT->getParamType(i), |
| 2756 |
"Argument value does not match function argument type!", &Arg, |
2756 |
"Argument value does not match function argument type!", &Arg, |
| 2757 |
FT->getParamType(i)); |
2757 |
FT->getParamType(i)); |
| 2758 |
Check(Arg.getType()->isFirstClassType(), |
2758 |
Check(Arg.getType()->isFirstClassType(), |
| 2759 |
"Function arguments must have first-class types!", &Arg); |
2759 |
"Function arguments must have first-class types!", &Arg); |
| 2760 |
if (!IsIntrinsic) { |
2760 |
if (!IsIntrinsic) { |
| 2761 |
Check(!Arg.getType()->isMetadataTy(), |
2761 |
Check(!Arg.getType()->isMetadataTy(), |
| 2762 |
"Function takes metadata but isn't an intrinsic", &Arg, &F); |
2762 |
"Function takes metadata but isn't an intrinsic", &Arg, &F); |
| 2763 |
Check(!Arg.getType()->isTokenTy(), |
2763 |
Check(!Arg.getType()->isTokenTy(), |
| 2764 |
"Function takes token but isn't an intrinsic", &Arg, &F); |
2764 |
"Function takes token but isn't an intrinsic", &Arg, &F); |
| 2765 |
Check(!Arg.getType()->isX86_AMXTy(), |
2765 |
Check(!Arg.getType()->isX86_AMXTy(), |
| 2766 |
"Function takes x86_amx but isn't an intrinsic", &Arg, &F); |
2766 |
"Function takes x86_amx but isn't an intrinsic", &Arg, &F); |
| 2767 |
} |
2767 |
} |
| 2768 |
|
2768 |
|
| 2769 |
// Check that swifterror argument is only used by loads and stores. |
2769 |
// Check that swifterror argument is only used by loads and stores. |
| 2770 |
if (Attrs.hasParamAttr(i, Attribute::SwiftError)) { |
2770 |
if (Attrs.hasParamAttr(i, Attribute::SwiftError)) { |
| 2771 |
verifySwiftErrorValue(&Arg); |
2771 |
verifySwiftErrorValue(&Arg); |
| 2772 |
} |
2772 |
} |
| 2773 |
++i; |
2773 |
++i; |
| 2774 |
} |
2774 |
} |
| 2775 |
|
2775 |
|
| 2776 |
if (!IsIntrinsic) { |
2776 |
if (!IsIntrinsic) { |
| 2777 |
Check(!F.getReturnType()->isTokenTy(), |
2777 |
Check(!F.getReturnType()->isTokenTy(), |
| 2778 |
"Function returns a token but isn't an intrinsic", &F); |
2778 |
"Function returns a token but isn't an intrinsic", &F); |
| 2779 |
Check(!F.getReturnType()->isX86_AMXTy(), |
2779 |
Check(!F.getReturnType()->isX86_AMXTy(), |
| 2780 |
"Function returns a x86_amx but isn't an intrinsic", &F); |
2780 |
"Function returns a x86_amx but isn't an intrinsic", &F); |
| 2781 |
} |
2781 |
} |
| 2782 |
|
2782 |
|
| 2783 |
// Get the function metadata attachments. |
2783 |
// Get the function metadata attachments. |
| 2784 |
SmallVector, 4> MDs; |
2784 |
SmallVector, 4> MDs; |
| 2785 |
F.getAllMetadata(MDs); |
2785 |
F.getAllMetadata(MDs); |
| 2786 |
assert(F.hasMetadata() != MDs.empty() && "Bit out-of-sync"); |
2786 |
assert(F.hasMetadata() != MDs.empty() && "Bit out-of-sync"); |
| 2787 |
verifyFunctionMetadata(MDs); |
2787 |
verifyFunctionMetadata(MDs); |
| 2788 |
|
2788 |
|
| 2789 |
// Check validity of the personality function |
2789 |
// Check validity of the personality function |
| 2790 |
if (F.hasPersonalityFn()) { |
2790 |
if (F.hasPersonalityFn()) { |
| 2791 |
auto *Per = dyn_cast(F.getPersonalityFn()->stripPointerCasts()); |
2791 |
auto *Per = dyn_cast(F.getPersonalityFn()->stripPointerCasts()); |
| 2792 |
if (Per) |
2792 |
if (Per) |
| 2793 |
Check(Per->getParent() == F.getParent(), |
2793 |
Check(Per->getParent() == F.getParent(), |
| 2794 |
"Referencing personality function in another module!", &F, |
2794 |
"Referencing personality function in another module!", &F, |
| 2795 |
F.getParent(), Per, Per->getParent()); |
2795 |
F.getParent(), Per, Per->getParent()); |
| 2796 |
} |
2796 |
} |
| 2797 |
|
2797 |
|
| 2798 |
// EH funclet coloring can be expensive, recompute on-demand |
2798 |
// EH funclet coloring can be expensive, recompute on-demand |
| 2799 |
BlockEHFuncletColors.clear(); |
2799 |
BlockEHFuncletColors.clear(); |
| 2800 |
|
2800 |
|
| 2801 |
if (F.isMaterializable()) { |
2801 |
if (F.isMaterializable()) { |
| 2802 |
// Function has a body somewhere we can't see. |
2802 |
// Function has a body somewhere we can't see. |
| 2803 |
Check(MDs.empty(), "unmaterialized function cannot have metadata", &F, |
2803 |
Check(MDs.empty(), "unmaterialized function cannot have metadata", &F, |
| 2804 |
MDs.empty() ? nullptr : MDs.front().second); |
2804 |
MDs.empty() ? nullptr : MDs.front().second); |
| 2805 |
} else if (F.isDeclaration()) { |
2805 |
} else if (F.isDeclaration()) { |
| 2806 |
for (const auto &I : MDs) { |
2806 |
for (const auto &I : MDs) { |
| 2807 |
// This is used for call site debug information. |
2807 |
// This is used for call site debug information. |
| 2808 |
CheckDI(I.first != LLVMContext::MD_dbg || |
2808 |
CheckDI(I.first != LLVMContext::MD_dbg || |
| 2809 |
!cast(I.second)->isDistinct(), |
2809 |
!cast(I.second)->isDistinct(), |
| 2810 |
"function declaration may only have a unique !dbg attachment", |
2810 |
"function declaration may only have a unique !dbg attachment", |
| 2811 |
&F); |
2811 |
&F); |
| 2812 |
Check(I.first != LLVMContext::MD_prof, |
2812 |
Check(I.first != LLVMContext::MD_prof, |
| 2813 |
"function declaration may not have a !prof attachment", &F); |
2813 |
"function declaration may not have a !prof attachment", &F); |
| 2814 |
|
2814 |
|
| 2815 |
// Verify the metadata itself. |
2815 |
// Verify the metadata itself. |
| 2816 |
visitMDNode(*I.second, AreDebugLocsAllowed::Yes); |
2816 |
visitMDNode(*I.second, AreDebugLocsAllowed::Yes); |
| 2817 |
} |
2817 |
} |
| 2818 |
Check(!F.hasPersonalityFn(), |
2818 |
Check(!F.hasPersonalityFn(), |
| 2819 |
"Function declaration shouldn't have a personality routine", &F); |
2819 |
"Function declaration shouldn't have a personality routine", &F); |
| 2820 |
} else { |
2820 |
} else { |
| 2821 |
// Verify that this function (which has a body) is not named "llvm.*". It |
2821 |
// Verify that this function (which has a body) is not named "llvm.*". It |
| 2822 |
// is not legal to define intrinsics. |
2822 |
// is not legal to define intrinsics. |
| 2823 |
Check(!IsIntrinsic, "llvm intrinsics cannot be defined!", &F); |
2823 |
Check(!IsIntrinsic, "llvm intrinsics cannot be defined!", &F); |
| 2824 |
|
2824 |
|
| 2825 |
// Check the entry node |
2825 |
// Check the entry node |
| 2826 |
const BasicBlock *Entry = &F.getEntryBlock(); |
2826 |
const BasicBlock *Entry = &F.getEntryBlock(); |
| 2827 |
Check(pred_empty(Entry), |
2827 |
Check(pred_empty(Entry), |
| 2828 |
"Entry block to function must not have predecessors!", Entry); |
2828 |
"Entry block to function must not have predecessors!", Entry); |
| 2829 |
|
2829 |
|
| 2830 |
// The address of the entry block cannot be taken, unless it is dead. |
2830 |
// The address of the entry block cannot be taken, unless it is dead. |
| 2831 |
if (Entry->hasAddressTaken()) { |
2831 |
if (Entry->hasAddressTaken()) { |
| 2832 |
Check(!BlockAddress::lookup(Entry)->isConstantUsed(), |
2832 |
Check(!BlockAddress::lookup(Entry)->isConstantUsed(), |
| 2833 |
"blockaddress may not be used with the entry block!", Entry); |
2833 |
"blockaddress may not be used with the entry block!", Entry); |
| 2834 |
} |
2834 |
} |
| 2835 |
|
2835 |
|
| 2836 |
unsigned NumDebugAttachments = 0, NumProfAttachments = 0, |
2836 |
unsigned NumDebugAttachments = 0, NumProfAttachments = 0, |
| 2837 |
NumKCFIAttachments = 0; |
2837 |
NumKCFIAttachments = 0; |
| 2838 |
// Visit metadata attachments. |
2838 |
// Visit metadata attachments. |
| 2839 |
for (const auto &I : MDs) { |
2839 |
for (const auto &I : MDs) { |
| 2840 |
// Verify that the attachment is legal. |
2840 |
// Verify that the attachment is legal. |
| 2841 |
auto AllowLocs = AreDebugLocsAllowed::No; |
2841 |
auto AllowLocs = AreDebugLocsAllowed::No; |
| 2842 |
switch (I.first) { |
2842 |
switch (I.first) { |
| 2843 |
default: |
2843 |
default: |
| 2844 |
break; |
2844 |
break; |
| 2845 |
case LLVMContext::MD_dbg: { |
2845 |
case LLVMContext::MD_dbg: { |
| 2846 |
++NumDebugAttachments; |
2846 |
++NumDebugAttachments; |
| 2847 |
CheckDI(NumDebugAttachments == 1, |
2847 |
CheckDI(NumDebugAttachments == 1, |
| 2848 |
"function must have a single !dbg attachment", &F, I.second); |
2848 |
"function must have a single !dbg attachment", &F, I.second); |
| 2849 |
CheckDI(isa(I.second), |
2849 |
CheckDI(isa(I.second), |
| 2850 |
"function !dbg attachment must be a subprogram", &F, I.second); |
2850 |
"function !dbg attachment must be a subprogram", &F, I.second); |
| 2851 |
CheckDI(cast(I.second)->isDistinct(), |
2851 |
CheckDI(cast(I.second)->isDistinct(), |
| 2852 |
"function definition may only have a distinct !dbg attachment", |
2852 |
"function definition may only have a distinct !dbg attachment", |
| 2853 |
&F); |
2853 |
&F); |
| 2854 |
|
2854 |
|
| 2855 |
auto *SP = cast(I.second); |
2855 |
auto *SP = cast(I.second); |
| 2856 |
const Function *&AttachedTo = DISubprogramAttachments[SP]; |
2856 |
const Function *&AttachedTo = DISubprogramAttachments[SP]; |
| 2857 |
CheckDI(!AttachedTo || AttachedTo == &F, |
2857 |
CheckDI(!AttachedTo || AttachedTo == &F, |
| 2858 |
"DISubprogram attached to more than one function", SP, &F); |
2858 |
"DISubprogram attached to more than one function", SP, &F); |
| 2859 |
AttachedTo = &F; |
2859 |
AttachedTo = &F; |
| 2860 |
AllowLocs = AreDebugLocsAllowed::Yes; |
2860 |
AllowLocs = AreDebugLocsAllowed::Yes; |
| 2861 |
break; |
2861 |
break; |
| 2862 |
} |
2862 |
} |
| 2863 |
case LLVMContext::MD_prof: |
2863 |
case LLVMContext::MD_prof: |
| 2864 |
++NumProfAttachments; |
2864 |
++NumProfAttachments; |
| 2865 |
Check(NumProfAttachments == 1, |
2865 |
Check(NumProfAttachments == 1, |
| 2866 |
"function must have a single !prof attachment", &F, I.second); |
2866 |
"function must have a single !prof attachment", &F, I.second); |
| 2867 |
break; |
2867 |
break; |
| 2868 |
case LLVMContext::MD_kcfi_type: |
2868 |
case LLVMContext::MD_kcfi_type: |
| 2869 |
++NumKCFIAttachments; |
2869 |
++NumKCFIAttachments; |
| 2870 |
Check(NumKCFIAttachments == 1, |
2870 |
Check(NumKCFIAttachments == 1, |
| 2871 |
"function must have a single !kcfi_type attachment", &F, |
2871 |
"function must have a single !kcfi_type attachment", &F, |
| 2872 |
I.second); |
2872 |
I.second); |
| 2873 |
break; |
2873 |
break; |
| 2874 |
} |
2874 |
} |
| 2875 |
|
2875 |
|
| 2876 |
// Verify the metadata itself. |
2876 |
// Verify the metadata itself. |
| 2877 |
visitMDNode(*I.second, AllowLocs); |
2877 |
visitMDNode(*I.second, AllowLocs); |
| 2878 |
} |
2878 |
} |
| 2879 |
} |
2879 |
} |
| 2880 |
|
2880 |
|
| 2881 |
// If this function is actually an intrinsic, verify that it is only used in |
2881 |
// If this function is actually an intrinsic, verify that it is only used in |
| 2882 |
// direct call/invokes, never having its "address taken". |
2882 |
// direct call/invokes, never having its "address taken". |
| 2883 |
// Only do this if the module is materialized, otherwise we don't have all the |
2883 |
// Only do this if the module is materialized, otherwise we don't have all the |
| 2884 |
// uses. |
2884 |
// uses. |
| 2885 |
if (F.isIntrinsic() && F.getParent()->isMaterialized()) { |
2885 |
if (F.isIntrinsic() && F.getParent()->isMaterialized()) { |
| 2886 |
const User *U; |
2886 |
const User *U; |
| 2887 |
if (F.hasAddressTaken(&U, false, true, false, |
2887 |
if (F.hasAddressTaken(&U, false, true, false, |
| 2888 |
/*IgnoreARCAttachedCall=*/true)) |
2888 |
/*IgnoreARCAttachedCall=*/true)) |
| 2889 |
Check(false, "Invalid user of intrinsic instruction!", U); |
2889 |
Check(false, "Invalid user of intrinsic instruction!", U); |
| 2890 |
} |
2890 |
} |
| 2891 |
|
2891 |
|
| 2892 |
// Check intrinsics' signatures. |
2892 |
// Check intrinsics' signatures. |
| 2893 |
switch (F.getIntrinsicID()) { |
2893 |
switch (F.getIntrinsicID()) { |
| 2894 |
case Intrinsic::experimental_gc_get_pointer_base: { |
2894 |
case Intrinsic::experimental_gc_get_pointer_base: { |
| 2895 |
FunctionType *FT = F.getFunctionType(); |
2895 |
FunctionType *FT = F.getFunctionType(); |
| 2896 |
Check(FT->getNumParams() == 1, "wrong number of parameters", F); |
2896 |
Check(FT->getNumParams() == 1, "wrong number of parameters", F); |
| 2897 |
Check(isa(F.getReturnType()), |
2897 |
Check(isa(F.getReturnType()), |
| 2898 |
"gc.get.pointer.base must return a pointer", F); |
2898 |
"gc.get.pointer.base must return a pointer", F); |
| 2899 |
Check(FT->getParamType(0) == F.getReturnType(), |
2899 |
Check(FT->getParamType(0) == F.getReturnType(), |
| 2900 |
"gc.get.pointer.base operand and result must be of the same type", F); |
2900 |
"gc.get.pointer.base operand and result must be of the same type", F); |
| 2901 |
break; |
2901 |
break; |
| 2902 |
} |
2902 |
} |
| 2903 |
case Intrinsic::experimental_gc_get_pointer_offset: { |
2903 |
case Intrinsic::experimental_gc_get_pointer_offset: { |
| 2904 |
FunctionType *FT = F.getFunctionType(); |
2904 |
FunctionType *FT = F.getFunctionType(); |
| 2905 |
Check(FT->getNumParams() == 1, "wrong number of parameters", F); |
2905 |
Check(FT->getNumParams() == 1, "wrong number of parameters", F); |
| 2906 |
Check(isa(FT->getParamType(0)), |
2906 |
Check(isa(FT->getParamType(0)), |
| 2907 |
"gc.get.pointer.offset operand must be a pointer", F); |
2907 |
"gc.get.pointer.offset operand must be a pointer", F); |
| 2908 |
Check(F.getReturnType()->isIntegerTy(), |
2908 |
Check(F.getReturnType()->isIntegerTy(), |
| 2909 |
"gc.get.pointer.offset must return integer", F); |
2909 |
"gc.get.pointer.offset must return integer", F); |
| 2910 |
break; |
2910 |
break; |
| 2911 |
} |
2911 |
} |
| 2912 |
} |
2912 |
} |
| 2913 |
|
2913 |
|
| 2914 |
auto *N = F.getSubprogram(); |
2914 |
auto *N = F.getSubprogram(); |
| 2915 |
HasDebugInfo = (N != nullptr); |
2915 |
HasDebugInfo = (N != nullptr); |
| 2916 |
if (!HasDebugInfo) |
2916 |
if (!HasDebugInfo) |
| 2917 |
return; |
2917 |
return; |
| 2918 |
|
2918 |
|
| 2919 |
// Check that all !dbg attachments lead to back to N. |
2919 |
// Check that all !dbg attachments lead to back to N. |
| 2920 |
// |
2920 |
// |
| 2921 |
// FIXME: Check this incrementally while visiting !dbg attachments. |
2921 |
// FIXME: Check this incrementally while visiting !dbg attachments. |
| 2922 |
// FIXME: Only check when N is the canonical subprogram for F. |
2922 |
// FIXME: Only check when N is the canonical subprogram for F. |
| 2923 |
SmallPtrSet Seen; |
2923 |
SmallPtrSet Seen; |
| 2924 |
auto VisitDebugLoc = [&](const Instruction &I, const MDNode *Node) { |
2924 |
auto VisitDebugLoc = [&](const Instruction &I, const MDNode *Node) { |
| 2925 |
// Be careful about using DILocation here since we might be dealing with |
2925 |
// Be careful about using DILocation here since we might be dealing with |
| 2926 |
// broken code (this is the Verifier after all). |
2926 |
// broken code (this is the Verifier after all). |
| 2927 |
const DILocation *DL = dyn_cast_or_null(Node); |
2927 |
const DILocation *DL = dyn_cast_or_null(Node); |
| 2928 |
if (!DL) |
2928 |
if (!DL) |
| 2929 |
return; |
2929 |
return; |
| 2930 |
if (!Seen.insert(DL).second) |
2930 |
if (!Seen.insert(DL).second) |
| 2931 |
return; |
2931 |
return; |
| 2932 |
|
2932 |
|
| 2933 |
Metadata *Parent = DL->getRawScope(); |
2933 |
Metadata *Parent = DL->getRawScope(); |
| 2934 |
CheckDI(Parent && isa(Parent), |
2934 |
CheckDI(Parent && isa(Parent), |
| 2935 |
"DILocation's scope must be a DILocalScope", N, &F, &I, DL, Parent); |
2935 |
"DILocation's scope must be a DILocalScope", N, &F, &I, DL, Parent); |
| 2936 |
|
2936 |
|
| 2937 |
DILocalScope *Scope = DL->getInlinedAtScope(); |
2937 |
DILocalScope *Scope = DL->getInlinedAtScope(); |
| 2938 |
Check(Scope, "Failed to find DILocalScope", DL); |
2938 |
Check(Scope, "Failed to find DILocalScope", DL); |
| 2939 |
|
2939 |
|
| 2940 |
if (!Seen.insert(Scope).second) |
2940 |
if (!Seen.insert(Scope).second) |
| 2941 |
return; |
2941 |
return; |
| 2942 |
|
2942 |
|
| 2943 |
DISubprogram *SP = Scope->getSubprogram(); |
2943 |
DISubprogram *SP = Scope->getSubprogram(); |
| 2944 |
|
2944 |
|
| 2945 |
// Scope and SP could be the same MDNode and we don't want to skip |
2945 |
// Scope and SP could be the same MDNode and we don't want to skip |
| 2946 |
// validation in that case |
2946 |
// validation in that case |
| 2947 |
if (SP && ((Scope != SP) && !Seen.insert(SP).second)) |
2947 |
if (SP && ((Scope != SP) && !Seen.insert(SP).second)) |
| 2948 |
return; |
2948 |
return; |
| 2949 |
|
2949 |
|
| 2950 |
CheckDI(SP->describes(&F), |
2950 |
CheckDI(SP->describes(&F), |
| 2951 |
"!dbg attachment points at wrong subprogram for function", N, &F, |
2951 |
"!dbg attachment points at wrong subprogram for function", N, &F, |
| 2952 |
&I, DL, Scope, SP); |
2952 |
&I, DL, Scope, SP); |
| 2953 |
}; |
2953 |
}; |
| 2954 |
for (auto &BB : F) |
2954 |
for (auto &BB : F) |
| 2955 |
for (auto &I : BB) { |
2955 |
for (auto &I : BB) { |
| 2956 |
VisitDebugLoc(I, I.getDebugLoc().getAsMDNode()); |
2956 |
VisitDebugLoc(I, I.getDebugLoc().getAsMDNode()); |
| 2957 |
// The llvm.loop annotations also contain two DILocations. |
2957 |
// The llvm.loop annotations also contain two DILocations. |
| 2958 |
if (auto MD = I.getMetadata(LLVMContext::MD_loop)) |
2958 |
if (auto MD = I.getMetadata(LLVMContext::MD_loop)) |
| 2959 |
for (unsigned i = 1; i < MD->getNumOperands(); ++i) |
2959 |
for (unsigned i = 1; i < MD->getNumOperands(); ++i) |
| 2960 |
VisitDebugLoc(I, dyn_cast_or_null(MD->getOperand(i))); |
2960 |
VisitDebugLoc(I, dyn_cast_or_null(MD->getOperand(i))); |
| 2961 |
if (BrokenDebugInfo) |
2961 |
if (BrokenDebugInfo) |
| 2962 |
return; |
2962 |
return; |
| 2963 |
} |
2963 |
} |
| 2964 |
} |
2964 |
} |
| 2965 |
|
2965 |
|
| 2966 |
// verifyBasicBlock - Verify that a basic block is well formed... |
2966 |
// verifyBasicBlock - Verify that a basic block is well formed... |
| 2967 |
// |
2967 |
// |
| 2968 |
void Verifier::visitBasicBlock(BasicBlock &BB) { |
2968 |
void Verifier::visitBasicBlock(BasicBlock &BB) { |
| 2969 |
InstsInThisBlock.clear(); |
2969 |
InstsInThisBlock.clear(); |
| 2970 |
|
2970 |
|
| 2971 |
// Ensure that basic blocks have terminators! |
2971 |
// Ensure that basic blocks have terminators! |
| 2972 |
Check(BB.getTerminator(), "Basic Block does not have terminator!", &BB); |
2972 |
Check(BB.getTerminator(), "Basic Block does not have terminator!", &BB); |
| 2973 |
|
2973 |
|
| 2974 |
// Check constraints that this basic block imposes on all of the PHI nodes in |
2974 |
// Check constraints that this basic block imposes on all of the PHI nodes in |
| 2975 |
// it. |
2975 |
// it. |
| 2976 |
if (isa(BB.front())) { |
2976 |
if (isa(BB.front())) { |
| 2977 |
SmallVector Preds(predecessors(&BB)); |
2977 |
SmallVector Preds(predecessors(&BB)); |
| 2978 |
SmallVector, 8> Values; |
2978 |
SmallVector, 8> Values; |
| 2979 |
llvm::sort(Preds); |
2979 |
llvm::sort(Preds); |
| 2980 |
for (const PHINode &PN : BB.phis()) { |
2980 |
for (const PHINode &PN : BB.phis()) { |
| 2981 |
Check(PN.getNumIncomingValues() == Preds.size(), |
2981 |
Check(PN.getNumIncomingValues() == Preds.size(), |
| 2982 |
"PHINode should have one entry for each predecessor of its " |
2982 |
"PHINode should have one entry for each predecessor of its " |
| 2983 |
"parent basic block!", |
2983 |
"parent basic block!", |
| 2984 |
&PN); |
2984 |
&PN); |
| 2985 |
|
2985 |
|
| 2986 |
// Get and sort all incoming values in the PHI node... |
2986 |
// Get and sort all incoming values in the PHI node... |
| 2987 |
Values.clear(); |
2987 |
Values.clear(); |
| 2988 |
Values.reserve(PN.getNumIncomingValues()); |
2988 |
Values.reserve(PN.getNumIncomingValues()); |
| 2989 |
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) |
2989 |
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) |
| 2990 |
Values.push_back( |
2990 |
Values.push_back( |
| 2991 |
std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i))); |
2991 |
std::make_pair(PN.getIncomingBlock(i), PN.getIncomingValue(i))); |
| 2992 |
llvm::sort(Values); |
2992 |
llvm::sort(Values); |
| 2993 |
|
2993 |
|
| 2994 |
for (unsigned i = 0, e = Values.size(); i != e; ++i) { |
2994 |
for (unsigned i = 0, e = Values.size(); i != e; ++i) { |
| 2995 |
// Check to make sure that if there is more than one entry for a |
2995 |
// Check to make sure that if there is more than one entry for a |
| 2996 |
// particular basic block in this PHI node, that the incoming values are |
2996 |
// particular basic block in this PHI node, that the incoming values are |
| 2997 |
// all identical. |
2997 |
// all identical. |
| 2998 |
// |
2998 |
// |
| 2999 |
Check(i == 0 || Values[i].first != Values[i - 1].first || |
2999 |
Check(i == 0 || Values[i].first != Values[i - 1].first || |
| 3000 |
Values[i].second == Values[i - 1].second, |
3000 |
Values[i].second == Values[i - 1].second, |
| 3001 |
"PHI node has multiple entries for the same basic block with " |
3001 |
"PHI node has multiple entries for the same basic block with " |
| 3002 |
"different incoming values!", |
3002 |
"different incoming values!", |
| 3003 |
&PN, Values[i].first, Values[i].second, Values[i - 1].second); |
3003 |
&PN, Values[i].first, Values[i].second, Values[i - 1].second); |
| 3004 |
|
3004 |
|
| 3005 |
// Check to make sure that the predecessors and PHI node entries are |
3005 |
// Check to make sure that the predecessors and PHI node entries are |
| 3006 |
// matched up. |
3006 |
// matched up. |
| 3007 |
Check(Values[i].first == Preds[i], |
3007 |
Check(Values[i].first == Preds[i], |
| 3008 |
"PHI node entries do not match predecessors!", &PN, |
3008 |
"PHI node entries do not match predecessors!", &PN, |
| 3009 |
Values[i].first, Preds[i]); |
3009 |
Values[i].first, Preds[i]); |
| 3010 |
} |
3010 |
} |
| 3011 |
} |
3011 |
} |
| 3012 |
} |
3012 |
} |
| 3013 |
|
3013 |
|
| 3014 |
// Check that all instructions have their parent pointers set up correctly. |
3014 |
// Check that all instructions have their parent pointers set up correctly. |
| 3015 |
for (auto &I : BB) |
3015 |
for (auto &I : BB) |
| 3016 |
{ |
3016 |
{ |
| 3017 |
Check(I.getParent() == &BB, "Instruction has bogus parent pointer!"); |
3017 |
Check(I.getParent() == &BB, "Instruction has bogus parent pointer!"); |
| 3018 |
} |
3018 |
} |
| 3019 |
} |
3019 |
} |
| 3020 |
|
3020 |
|
| 3021 |
void Verifier::visitTerminator(Instruction &I) { |
3021 |
void Verifier::visitTerminator(Instruction &I) { |
| 3022 |
// Ensure that terminators only exist at the end of the basic block. |
3022 |
// Ensure that terminators only exist at the end of the basic block. |
| 3023 |
Check(&I == I.getParent()->getTerminator(), |
3023 |
Check(&I == I.getParent()->getTerminator(), |
| 3024 |
"Terminator found in the middle of a basic block!", I.getParent()); |
3024 |
"Terminator found in the middle of a basic block!", I.getParent()); |
| 3025 |
visitInstruction(I); |
3025 |
visitInstruction(I); |
| 3026 |
} |
3026 |
} |
| 3027 |
|
3027 |
|
| 3028 |
void Verifier::visitBranchInst(BranchInst &BI) { |
3028 |
void Verifier::visitBranchInst(BranchInst &BI) { |
| 3029 |
if (BI.isConditional()) { |
3029 |
if (BI.isConditional()) { |
| 3030 |
Check(BI.getCondition()->getType()->isIntegerTy(1), |
3030 |
Check(BI.getCondition()->getType()->isIntegerTy(1), |
| 3031 |
"Branch condition is not 'i1' type!", &BI, BI.getCondition()); |
3031 |
"Branch condition is not 'i1' type!", &BI, BI.getCondition()); |
| 3032 |
} |
3032 |
} |
| 3033 |
visitTerminator(BI); |
3033 |
visitTerminator(BI); |
| 3034 |
} |
3034 |
} |
| 3035 |
|
3035 |
|
| 3036 |
void Verifier::visitReturnInst(ReturnInst &RI) { |
3036 |
void Verifier::visitReturnInst(ReturnInst &RI) { |
| 3037 |
Function *F = RI.getParent()->getParent(); |
3037 |
Function *F = RI.getParent()->getParent(); |
| 3038 |
unsigned N = RI.getNumOperands(); |
3038 |
unsigned N = RI.getNumOperands(); |
| 3039 |
if (F->getReturnType()->isVoidTy()) |
3039 |
if (F->getReturnType()->isVoidTy()) |
| 3040 |
Check(N == 0, |
3040 |
Check(N == 0, |
| 3041 |
"Found return instr that returns non-void in Function of void " |
3041 |
"Found return instr that returns non-void in Function of void " |
| 3042 |
"return type!", |
3042 |
"return type!", |
| 3043 |
&RI, F->getReturnType()); |
3043 |
&RI, F->getReturnType()); |
| 3044 |
else |
3044 |
else |
| 3045 |
Check(N == 1 && F->getReturnType() == RI.getOperand(0)->getType(), |
3045 |
Check(N == 1 && F->getReturnType() == RI.getOperand(0)->getType(), |
| 3046 |
"Function return type does not match operand " |
3046 |
"Function return type does not match operand " |
| 3047 |
"type of return inst!", |
3047 |
"type of return inst!", |
| 3048 |
&RI, F->getReturnType()); |
3048 |
&RI, F->getReturnType()); |
| 3049 |
|
3049 |
|
| 3050 |
// Check to make sure that the return value has necessary properties for |
3050 |
// Check to make sure that the return value has necessary properties for |
| 3051 |
// terminators... |
3051 |
// terminators... |
| 3052 |
visitTerminator(RI); |
3052 |
visitTerminator(RI); |
| 3053 |
} |
3053 |
} |
| 3054 |
|
3054 |
|
| 3055 |
void Verifier::visitSwitchInst(SwitchInst &SI) { |
3055 |
void Verifier::visitSwitchInst(SwitchInst &SI) { |
| 3056 |
Check(SI.getType()->isVoidTy(), "Switch must have void result type!", &SI); |
3056 |
Check(SI.getType()->isVoidTy(), "Switch must have void result type!", &SI); |
| 3057 |
// Check to make sure that all of the constants in the switch instruction |
3057 |
// Check to make sure that all of the constants in the switch instruction |
| 3058 |
// have the same type as the switched-on value. |
3058 |
// have the same type as the switched-on value. |
| 3059 |
Type *SwitchTy = SI.getCondition()->getType(); |
3059 |
Type *SwitchTy = SI.getCondition()->getType(); |
| 3060 |
SmallPtrSet Constants; |
3060 |
SmallPtrSet Constants; |
| 3061 |
for (auto &Case : SI.cases()) { |
3061 |
for (auto &Case : SI.cases()) { |
| 3062 |
Check(isa(SI.getOperand(Case.getCaseIndex() * 2 + 2)), |
3062 |
Check(isa(SI.getOperand(Case.getCaseIndex() * 2 + 2)), |
| 3063 |
"Case value is not a constant integer.", &SI); |
3063 |
"Case value is not a constant integer.", &SI); |
| 3064 |
Check(Case.getCaseValue()->getType() == SwitchTy, |
3064 |
Check(Case.getCaseValue()->getType() == SwitchTy, |
| 3065 |
"Switch constants must all be same type as switch value!", &SI); |
3065 |
"Switch constants must all be same type as switch value!", &SI); |
| 3066 |
Check(Constants.insert(Case.getCaseValue()).second, |
3066 |
Check(Constants.insert(Case.getCaseValue()).second, |
| 3067 |
"Duplicate integer as switch case", &SI, Case.getCaseValue()); |
3067 |
"Duplicate integer as switch case", &SI, Case.getCaseValue()); |
| 3068 |
} |
3068 |
} |
| 3069 |
|
3069 |
|
| 3070 |
visitTerminator(SI); |
3070 |
visitTerminator(SI); |
| 3071 |
} |
3071 |
} |
| 3072 |
|
3072 |
|
| 3073 |
void Verifier::visitIndirectBrInst(IndirectBrInst &BI) { |
3073 |
void Verifier::visitIndirectBrInst(IndirectBrInst &BI) { |
| 3074 |
Check(BI.getAddress()->getType()->isPointerTy(), |
3074 |
Check(BI.getAddress()->getType()->isPointerTy(), |
| 3075 |
"Indirectbr operand must have pointer type!", &BI); |
3075 |
"Indirectbr operand must have pointer type!", &BI); |
| 3076 |
for (unsigned i = 0, e = BI.getNumDestinations(); i != e; ++i) |
3076 |
for (unsigned i = 0, e = BI.getNumDestinations(); i != e; ++i) |
| 3077 |
Check(BI.getDestination(i)->getType()->isLabelTy(), |
3077 |
Check(BI.getDestination(i)->getType()->isLabelTy(), |
| 3078 |
"Indirectbr destinations must all have pointer type!", &BI); |
3078 |
"Indirectbr destinations must all have pointer type!", &BI); |
| 3079 |
|
3079 |
|
| 3080 |
visitTerminator(BI); |
3080 |
visitTerminator(BI); |
| 3081 |
} |
3081 |
} |
| 3082 |
|
3082 |
|
| 3083 |
void Verifier::visitCallBrInst(CallBrInst &CBI) { |
3083 |
void Verifier::visitCallBrInst(CallBrInst &CBI) { |
| 3084 |
Check(CBI.isInlineAsm(), "Callbr is currently only used for asm-goto!", &CBI); |
3084 |
Check(CBI.isInlineAsm(), "Callbr is currently only used for asm-goto!", &CBI); |
| 3085 |
const InlineAsm *IA = cast(CBI.getCalledOperand()); |
3085 |
const InlineAsm *IA = cast(CBI.getCalledOperand()); |
| 3086 |
Check(!IA->canThrow(), "Unwinding from Callbr is not allowed"); |
3086 |
Check(!IA->canThrow(), "Unwinding from Callbr is not allowed"); |
| 3087 |
|
3087 |
|
| 3088 |
verifyInlineAsmCall(CBI); |
3088 |
verifyInlineAsmCall(CBI); |
| 3089 |
visitTerminator(CBI); |
3089 |
visitTerminator(CBI); |
| 3090 |
} |
3090 |
} |
| 3091 |
|
3091 |
|
| 3092 |
void Verifier::visitSelectInst(SelectInst &SI) { |
3092 |
void Verifier::visitSelectInst(SelectInst &SI) { |
| 3093 |
Check(!SelectInst::areInvalidOperands(SI.getOperand(0), SI.getOperand(1), |
3093 |
Check(!SelectInst::areInvalidOperands(SI.getOperand(0), SI.getOperand(1), |
| 3094 |
SI.getOperand(2)), |
3094 |
SI.getOperand(2)), |
| 3095 |
"Invalid operands for select instruction!", &SI); |
3095 |
"Invalid operands for select instruction!", &SI); |
| 3096 |
|
3096 |
|
| 3097 |
Check(SI.getTrueValue()->getType() == SI.getType(), |
3097 |
Check(SI.getTrueValue()->getType() == SI.getType(), |
| 3098 |
"Select values must have same type as select instruction!", &SI); |
3098 |
"Select values must have same type as select instruction!", &SI); |
| 3099 |
visitInstruction(SI); |
3099 |
visitInstruction(SI); |
| 3100 |
} |
3100 |
} |
| 3101 |
|
3101 |
|
| 3102 |
/// visitUserOp1 - User defined operators shouldn't live beyond the lifetime of |
3102 |
/// visitUserOp1 - User defined operators shouldn't live beyond the lifetime of |
| 3103 |
/// a pass, if any exist, it's an error. |
3103 |
/// a pass, if any exist, it's an error. |
| 3104 |
/// |
3104 |
/// |
| 3105 |
void Verifier::visitUserOp1(Instruction &I) { |
3105 |
void Verifier::visitUserOp1(Instruction &I) { |
| 3106 |
Check(false, "User-defined operators should not live outside of a pass!", &I); |
3106 |
Check(false, "User-defined operators should not live outside of a pass!", &I); |
| 3107 |
} |
3107 |
} |
| 3108 |
|
3108 |
|
| 3109 |
void Verifier::visitTruncInst(TruncInst &I) { |
3109 |
void Verifier::visitTruncInst(TruncInst &I) { |
| 3110 |
// Get the source and destination types |
3110 |
// Get the source and destination types |
| 3111 |
Type *SrcTy = I.getOperand(0)->getType(); |
3111 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3112 |
Type *DestTy = I.getType(); |
3112 |
Type *DestTy = I.getType(); |
| 3113 |
|
3113 |
|
| 3114 |
// Get the size of the types in bits, we'll need this later |
3114 |
// Get the size of the types in bits, we'll need this later |
| 3115 |
unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); |
3115 |
unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); |
| 3116 |
unsigned DestBitSize = DestTy->getScalarSizeInBits(); |
3116 |
unsigned DestBitSize = DestTy->getScalarSizeInBits(); |
| 3117 |
|
3117 |
|
| 3118 |
Check(SrcTy->isIntOrIntVectorTy(), "Trunc only operates on integer", &I); |
3118 |
Check(SrcTy->isIntOrIntVectorTy(), "Trunc only operates on integer", &I); |
| 3119 |
Check(DestTy->isIntOrIntVectorTy(), "Trunc only produces integer", &I); |
3119 |
Check(DestTy->isIntOrIntVectorTy(), "Trunc only produces integer", &I); |
| 3120 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), |
3120 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), |
| 3121 |
"trunc source and destination must both be a vector or neither", &I); |
3121 |
"trunc source and destination must both be a vector or neither", &I); |
| 3122 |
Check(SrcBitSize > DestBitSize, "DestTy too big for Trunc", &I); |
3122 |
Check(SrcBitSize > DestBitSize, "DestTy too big for Trunc", &I); |
| 3123 |
|
3123 |
|
| 3124 |
visitInstruction(I); |
3124 |
visitInstruction(I); |
| 3125 |
} |
3125 |
} |
| 3126 |
|
3126 |
|
| 3127 |
void Verifier::visitZExtInst(ZExtInst &I) { |
3127 |
void Verifier::visitZExtInst(ZExtInst &I) { |
| 3128 |
// Get the source and destination types |
3128 |
// Get the source and destination types |
| 3129 |
Type *SrcTy = I.getOperand(0)->getType(); |
3129 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3130 |
Type *DestTy = I.getType(); |
3130 |
Type *DestTy = I.getType(); |
| 3131 |
|
3131 |
|
| 3132 |
// Get the size of the types in bits, we'll need this later |
3132 |
// Get the size of the types in bits, we'll need this later |
| 3133 |
Check(SrcTy->isIntOrIntVectorTy(), "ZExt only operates on integer", &I); |
3133 |
Check(SrcTy->isIntOrIntVectorTy(), "ZExt only operates on integer", &I); |
| 3134 |
Check(DestTy->isIntOrIntVectorTy(), "ZExt only produces an integer", &I); |
3134 |
Check(DestTy->isIntOrIntVectorTy(), "ZExt only produces an integer", &I); |
| 3135 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), |
3135 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), |
| 3136 |
"zext source and destination must both be a vector or neither", &I); |
3136 |
"zext source and destination must both be a vector or neither", &I); |
| 3137 |
unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); |
3137 |
unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); |
| 3138 |
unsigned DestBitSize = DestTy->getScalarSizeInBits(); |
3138 |
unsigned DestBitSize = DestTy->getScalarSizeInBits(); |
| 3139 |
|
3139 |
|
| 3140 |
Check(SrcBitSize < DestBitSize, "Type too small for ZExt", &I); |
3140 |
Check(SrcBitSize < DestBitSize, "Type too small for ZExt", &I); |
| 3141 |
|
3141 |
|
| 3142 |
visitInstruction(I); |
3142 |
visitInstruction(I); |
| 3143 |
} |
3143 |
} |
| 3144 |
|
3144 |
|
| 3145 |
void Verifier::visitSExtInst(SExtInst &I) { |
3145 |
void Verifier::visitSExtInst(SExtInst &I) { |
| 3146 |
// Get the source and destination types |
3146 |
// Get the source and destination types |
| 3147 |
Type *SrcTy = I.getOperand(0)->getType(); |
3147 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3148 |
Type *DestTy = I.getType(); |
3148 |
Type *DestTy = I.getType(); |
| 3149 |
|
3149 |
|
| 3150 |
// Get the size of the types in bits, we'll need this later |
3150 |
// Get the size of the types in bits, we'll need this later |
| 3151 |
unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); |
3151 |
unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); |
| 3152 |
unsigned DestBitSize = DestTy->getScalarSizeInBits(); |
3152 |
unsigned DestBitSize = DestTy->getScalarSizeInBits(); |
| 3153 |
|
3153 |
|
| 3154 |
Check(SrcTy->isIntOrIntVectorTy(), "SExt only operates on integer", &I); |
3154 |
Check(SrcTy->isIntOrIntVectorTy(), "SExt only operates on integer", &I); |
| 3155 |
Check(DestTy->isIntOrIntVectorTy(), "SExt only produces an integer", &I); |
3155 |
Check(DestTy->isIntOrIntVectorTy(), "SExt only produces an integer", &I); |
| 3156 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), |
3156 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), |
| 3157 |
"sext source and destination must both be a vector or neither", &I); |
3157 |
"sext source and destination must both be a vector or neither", &I); |
| 3158 |
Check(SrcBitSize < DestBitSize, "Type too small for SExt", &I); |
3158 |
Check(SrcBitSize < DestBitSize, "Type too small for SExt", &I); |
| 3159 |
|
3159 |
|
| 3160 |
visitInstruction(I); |
3160 |
visitInstruction(I); |
| 3161 |
} |
3161 |
} |
| 3162 |
|
3162 |
|
| 3163 |
void Verifier::visitFPTruncInst(FPTruncInst &I) { |
3163 |
void Verifier::visitFPTruncInst(FPTruncInst &I) { |
| 3164 |
// Get the source and destination types |
3164 |
// Get the source and destination types |
| 3165 |
Type *SrcTy = I.getOperand(0)->getType(); |
3165 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3166 |
Type *DestTy = I.getType(); |
3166 |
Type *DestTy = I.getType(); |
| 3167 |
// Get the size of the types in bits, we'll need this later |
3167 |
// Get the size of the types in bits, we'll need this later |
| 3168 |
unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); |
3168 |
unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); |
| 3169 |
unsigned DestBitSize = DestTy->getScalarSizeInBits(); |
3169 |
unsigned DestBitSize = DestTy->getScalarSizeInBits(); |
| 3170 |
|
3170 |
|
| 3171 |
Check(SrcTy->isFPOrFPVectorTy(), "FPTrunc only operates on FP", &I); |
3171 |
Check(SrcTy->isFPOrFPVectorTy(), "FPTrunc only operates on FP", &I); |
| 3172 |
Check(DestTy->isFPOrFPVectorTy(), "FPTrunc only produces an FP", &I); |
3172 |
Check(DestTy->isFPOrFPVectorTy(), "FPTrunc only produces an FP", &I); |
| 3173 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), |
3173 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), |
| 3174 |
"fptrunc source and destination must both be a vector or neither", &I); |
3174 |
"fptrunc source and destination must both be a vector or neither", &I); |
| 3175 |
Check(SrcBitSize > DestBitSize, "DestTy too big for FPTrunc", &I); |
3175 |
Check(SrcBitSize > DestBitSize, "DestTy too big for FPTrunc", &I); |
| 3176 |
|
3176 |
|
| 3177 |
visitInstruction(I); |
3177 |
visitInstruction(I); |
| 3178 |
} |
3178 |
} |
| 3179 |
|
3179 |
|
| 3180 |
void Verifier::visitFPExtInst(FPExtInst &I) { |
3180 |
void Verifier::visitFPExtInst(FPExtInst &I) { |
| 3181 |
// Get the source and destination types |
3181 |
// Get the source and destination types |
| 3182 |
Type *SrcTy = I.getOperand(0)->getType(); |
3182 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3183 |
Type *DestTy = I.getType(); |
3183 |
Type *DestTy = I.getType(); |
| 3184 |
|
3184 |
|
| 3185 |
// Get the size of the types in bits, we'll need this later |
3185 |
// Get the size of the types in bits, we'll need this later |
| 3186 |
unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); |
3186 |
unsigned SrcBitSize = SrcTy->getScalarSizeInBits(); |
| 3187 |
unsigned DestBitSize = DestTy->getScalarSizeInBits(); |
3187 |
unsigned DestBitSize = DestTy->getScalarSizeInBits(); |
| 3188 |
|
3188 |
|
| 3189 |
Check(SrcTy->isFPOrFPVectorTy(), "FPExt only operates on FP", &I); |
3189 |
Check(SrcTy->isFPOrFPVectorTy(), "FPExt only operates on FP", &I); |
| 3190 |
Check(DestTy->isFPOrFPVectorTy(), "FPExt only produces an FP", &I); |
3190 |
Check(DestTy->isFPOrFPVectorTy(), "FPExt only produces an FP", &I); |
| 3191 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), |
3191 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), |
| 3192 |
"fpext source and destination must both be a vector or neither", &I); |
3192 |
"fpext source and destination must both be a vector or neither", &I); |
| 3193 |
Check(SrcBitSize < DestBitSize, "DestTy too small for FPExt", &I); |
3193 |
Check(SrcBitSize < DestBitSize, "DestTy too small for FPExt", &I); |
| 3194 |
|
3194 |
|
| 3195 |
visitInstruction(I); |
3195 |
visitInstruction(I); |
| 3196 |
} |
3196 |
} |
| 3197 |
|
3197 |
|
| 3198 |
void Verifier::visitUIToFPInst(UIToFPInst &I) { |
3198 |
void Verifier::visitUIToFPInst(UIToFPInst &I) { |
| 3199 |
// Get the source and destination types |
3199 |
// Get the source and destination types |
| 3200 |
Type *SrcTy = I.getOperand(0)->getType(); |
3200 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3201 |
Type *DestTy = I.getType(); |
3201 |
Type *DestTy = I.getType(); |
| 3202 |
|
3202 |
|
| 3203 |
bool SrcVec = SrcTy->isVectorTy(); |
3203 |
bool SrcVec = SrcTy->isVectorTy(); |
| 3204 |
bool DstVec = DestTy->isVectorTy(); |
3204 |
bool DstVec = DestTy->isVectorTy(); |
| 3205 |
|
3205 |
|
| 3206 |
Check(SrcVec == DstVec, |
3206 |
Check(SrcVec == DstVec, |
| 3207 |
"UIToFP source and dest must both be vector or scalar", &I); |
3207 |
"UIToFP source and dest must both be vector or scalar", &I); |
| 3208 |
Check(SrcTy->isIntOrIntVectorTy(), |
3208 |
Check(SrcTy->isIntOrIntVectorTy(), |
| 3209 |
"UIToFP source must be integer or integer vector", &I); |
3209 |
"UIToFP source must be integer or integer vector", &I); |
| 3210 |
Check(DestTy->isFPOrFPVectorTy(), "UIToFP result must be FP or FP vector", |
3210 |
Check(DestTy->isFPOrFPVectorTy(), "UIToFP result must be FP or FP vector", |
| 3211 |
&I); |
3211 |
&I); |
| 3212 |
|
3212 |
|
| 3213 |
if (SrcVec && DstVec) |
3213 |
if (SrcVec && DstVec) |
| 3214 |
Check(cast(SrcTy)->getElementCount() == |
3214 |
Check(cast(SrcTy)->getElementCount() == |
| 3215 |
cast(DestTy)->getElementCount(), |
3215 |
cast(DestTy)->getElementCount(), |
| 3216 |
"UIToFP source and dest vector length mismatch", &I); |
3216 |
"UIToFP source and dest vector length mismatch", &I); |
| 3217 |
|
3217 |
|
| 3218 |
visitInstruction(I); |
3218 |
visitInstruction(I); |
| 3219 |
} |
3219 |
} |
| 3220 |
|
3220 |
|
| 3221 |
void Verifier::visitSIToFPInst(SIToFPInst &I) { |
3221 |
void Verifier::visitSIToFPInst(SIToFPInst &I) { |
| 3222 |
// Get the source and destination types |
3222 |
// Get the source and destination types |
| 3223 |
Type *SrcTy = I.getOperand(0)->getType(); |
3223 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3224 |
Type *DestTy = I.getType(); |
3224 |
Type *DestTy = I.getType(); |
| 3225 |
|
3225 |
|
| 3226 |
bool SrcVec = SrcTy->isVectorTy(); |
3226 |
bool SrcVec = SrcTy->isVectorTy(); |
| 3227 |
bool DstVec = DestTy->isVectorTy(); |
3227 |
bool DstVec = DestTy->isVectorTy(); |
| 3228 |
|
3228 |
|
| 3229 |
Check(SrcVec == DstVec, |
3229 |
Check(SrcVec == DstVec, |
| 3230 |
"SIToFP source and dest must both be vector or scalar", &I); |
3230 |
"SIToFP source and dest must both be vector or scalar", &I); |
| 3231 |
Check(SrcTy->isIntOrIntVectorTy(), |
3231 |
Check(SrcTy->isIntOrIntVectorTy(), |
| 3232 |
"SIToFP source must be integer or integer vector", &I); |
3232 |
"SIToFP source must be integer or integer vector", &I); |
| 3233 |
Check(DestTy->isFPOrFPVectorTy(), "SIToFP result must be FP or FP vector", |
3233 |
Check(DestTy->isFPOrFPVectorTy(), "SIToFP result must be FP or FP vector", |
| 3234 |
&I); |
3234 |
&I); |
| 3235 |
|
3235 |
|
| 3236 |
if (SrcVec && DstVec) |
3236 |
if (SrcVec && DstVec) |
| 3237 |
Check(cast(SrcTy)->getElementCount() == |
3237 |
Check(cast(SrcTy)->getElementCount() == |
| 3238 |
cast(DestTy)->getElementCount(), |
3238 |
cast(DestTy)->getElementCount(), |
| 3239 |
"SIToFP source and dest vector length mismatch", &I); |
3239 |
"SIToFP source and dest vector length mismatch", &I); |
| 3240 |
|
3240 |
|
| 3241 |
visitInstruction(I); |
3241 |
visitInstruction(I); |
| 3242 |
} |
3242 |
} |
| 3243 |
|
3243 |
|
| 3244 |
void Verifier::visitFPToUIInst(FPToUIInst &I) { |
3244 |
void Verifier::visitFPToUIInst(FPToUIInst &I) { |
| 3245 |
// Get the source and destination types |
3245 |
// Get the source and destination types |
| 3246 |
Type *SrcTy = I.getOperand(0)->getType(); |
3246 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3247 |
Type *DestTy = I.getType(); |
3247 |
Type *DestTy = I.getType(); |
| 3248 |
|
3248 |
|
| 3249 |
bool SrcVec = SrcTy->isVectorTy(); |
3249 |
bool SrcVec = SrcTy->isVectorTy(); |
| 3250 |
bool DstVec = DestTy->isVectorTy(); |
3250 |
bool DstVec = DestTy->isVectorTy(); |
| 3251 |
|
3251 |
|
| 3252 |
Check(SrcVec == DstVec, |
3252 |
Check(SrcVec == DstVec, |
| 3253 |
"FPToUI source and dest must both be vector or scalar", &I); |
3253 |
"FPToUI source and dest must both be vector or scalar", &I); |
| 3254 |
Check(SrcTy->isFPOrFPVectorTy(), "FPToUI source must be FP or FP vector", &I); |
3254 |
Check(SrcTy->isFPOrFPVectorTy(), "FPToUI source must be FP or FP vector", &I); |
| 3255 |
Check(DestTy->isIntOrIntVectorTy(), |
3255 |
Check(DestTy->isIntOrIntVectorTy(), |
| 3256 |
"FPToUI result must be integer or integer vector", &I); |
3256 |
"FPToUI result must be integer or integer vector", &I); |
| 3257 |
|
3257 |
|
| 3258 |
if (SrcVec && DstVec) |
3258 |
if (SrcVec && DstVec) |
| 3259 |
Check(cast(SrcTy)->getElementCount() == |
3259 |
Check(cast(SrcTy)->getElementCount() == |
| 3260 |
cast(DestTy)->getElementCount(), |
3260 |
cast(DestTy)->getElementCount(), |
| 3261 |
"FPToUI source and dest vector length mismatch", &I); |
3261 |
"FPToUI source and dest vector length mismatch", &I); |
| 3262 |
|
3262 |
|
| 3263 |
visitInstruction(I); |
3263 |
visitInstruction(I); |
| 3264 |
} |
3264 |
} |
| 3265 |
|
3265 |
|
| 3266 |
void Verifier::visitFPToSIInst(FPToSIInst &I) { |
3266 |
void Verifier::visitFPToSIInst(FPToSIInst &I) { |
| 3267 |
// Get the source and destination types |
3267 |
// Get the source and destination types |
| 3268 |
Type *SrcTy = I.getOperand(0)->getType(); |
3268 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3269 |
Type *DestTy = I.getType(); |
3269 |
Type *DestTy = I.getType(); |
| 3270 |
|
3270 |
|
| 3271 |
bool SrcVec = SrcTy->isVectorTy(); |
3271 |
bool SrcVec = SrcTy->isVectorTy(); |
| 3272 |
bool DstVec = DestTy->isVectorTy(); |
3272 |
bool DstVec = DestTy->isVectorTy(); |
| 3273 |
|
3273 |
|
| 3274 |
Check(SrcVec == DstVec, |
3274 |
Check(SrcVec == DstVec, |
| 3275 |
"FPToSI source and dest must both be vector or scalar", &I); |
3275 |
"FPToSI source and dest must both be vector or scalar", &I); |
| 3276 |
Check(SrcTy->isFPOrFPVectorTy(), "FPToSI source must be FP or FP vector", &I); |
3276 |
Check(SrcTy->isFPOrFPVectorTy(), "FPToSI source must be FP or FP vector", &I); |
| 3277 |
Check(DestTy->isIntOrIntVectorTy(), |
3277 |
Check(DestTy->isIntOrIntVectorTy(), |
| 3278 |
"FPToSI result must be integer or integer vector", &I); |
3278 |
"FPToSI result must be integer or integer vector", &I); |
| 3279 |
|
3279 |
|
| 3280 |
if (SrcVec && DstVec) |
3280 |
if (SrcVec && DstVec) |
| 3281 |
Check(cast(SrcTy)->getElementCount() == |
3281 |
Check(cast(SrcTy)->getElementCount() == |
| 3282 |
cast(DestTy)->getElementCount(), |
3282 |
cast(DestTy)->getElementCount(), |
| 3283 |
"FPToSI source and dest vector length mismatch", &I); |
3283 |
"FPToSI source and dest vector length mismatch", &I); |
| 3284 |
|
3284 |
|
| 3285 |
visitInstruction(I); |
3285 |
visitInstruction(I); |
| 3286 |
} |
3286 |
} |
| 3287 |
|
3287 |
|
| 3288 |
void Verifier::visitPtrToIntInst(PtrToIntInst &I) { |
3288 |
void Verifier::visitPtrToIntInst(PtrToIntInst &I) { |
| 3289 |
// Get the source and destination types |
3289 |
// Get the source and destination types |
| 3290 |
Type *SrcTy = I.getOperand(0)->getType(); |
3290 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3291 |
Type *DestTy = I.getType(); |
3291 |
Type *DestTy = I.getType(); |
| 3292 |
|
3292 |
|
| 3293 |
Check(SrcTy->isPtrOrPtrVectorTy(), "PtrToInt source must be pointer", &I); |
3293 |
Check(SrcTy->isPtrOrPtrVectorTy(), "PtrToInt source must be pointer", &I); |
| 3294 |
|
3294 |
|
| 3295 |
Check(DestTy->isIntOrIntVectorTy(), "PtrToInt result must be integral", &I); |
3295 |
Check(DestTy->isIntOrIntVectorTy(), "PtrToInt result must be integral", &I); |
| 3296 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), "PtrToInt type mismatch", |
3296 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), "PtrToInt type mismatch", |
| 3297 |
&I); |
3297 |
&I); |
| 3298 |
|
3298 |
|
| 3299 |
if (SrcTy->isVectorTy()) { |
3299 |
if (SrcTy->isVectorTy()) { |
| 3300 |
auto *VSrc = cast(SrcTy); |
3300 |
auto *VSrc = cast(SrcTy); |
| 3301 |
auto *VDest = cast(DestTy); |
3301 |
auto *VDest = cast(DestTy); |
| 3302 |
Check(VSrc->getElementCount() == VDest->getElementCount(), |
3302 |
Check(VSrc->getElementCount() == VDest->getElementCount(), |
| 3303 |
"PtrToInt Vector width mismatch", &I); |
3303 |
"PtrToInt Vector width mismatch", &I); |
| 3304 |
} |
3304 |
} |
| 3305 |
|
3305 |
|
| 3306 |
visitInstruction(I); |
3306 |
visitInstruction(I); |
| 3307 |
} |
3307 |
} |
| 3308 |
|
3308 |
|
| 3309 |
void Verifier::visitIntToPtrInst(IntToPtrInst &I) { |
3309 |
void Verifier::visitIntToPtrInst(IntToPtrInst &I) { |
| 3310 |
// Get the source and destination types |
3310 |
// Get the source and destination types |
| 3311 |
Type *SrcTy = I.getOperand(0)->getType(); |
3311 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3312 |
Type *DestTy = I.getType(); |
3312 |
Type *DestTy = I.getType(); |
| 3313 |
|
3313 |
|
| 3314 |
Check(SrcTy->isIntOrIntVectorTy(), "IntToPtr source must be an integral", &I); |
3314 |
Check(SrcTy->isIntOrIntVectorTy(), "IntToPtr source must be an integral", &I); |
| 3315 |
Check(DestTy->isPtrOrPtrVectorTy(), "IntToPtr result must be a pointer", &I); |
3315 |
Check(DestTy->isPtrOrPtrVectorTy(), "IntToPtr result must be a pointer", &I); |
| 3316 |
|
3316 |
|
| 3317 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), "IntToPtr type mismatch", |
3317 |
Check(SrcTy->isVectorTy() == DestTy->isVectorTy(), "IntToPtr type mismatch", |
| 3318 |
&I); |
3318 |
&I); |
| 3319 |
if (SrcTy->isVectorTy()) { |
3319 |
if (SrcTy->isVectorTy()) { |
| 3320 |
auto *VSrc = cast(SrcTy); |
3320 |
auto *VSrc = cast(SrcTy); |
| 3321 |
auto *VDest = cast(DestTy); |
3321 |
auto *VDest = cast(DestTy); |
| 3322 |
Check(VSrc->getElementCount() == VDest->getElementCount(), |
3322 |
Check(VSrc->getElementCount() == VDest->getElementCount(), |
| 3323 |
"IntToPtr Vector width mismatch", &I); |
3323 |
"IntToPtr Vector width mismatch", &I); |
| 3324 |
} |
3324 |
} |
| 3325 |
visitInstruction(I); |
3325 |
visitInstruction(I); |
| 3326 |
} |
3326 |
} |
| 3327 |
|
3327 |
|
| 3328 |
void Verifier::visitBitCastInst(BitCastInst &I) { |
3328 |
void Verifier::visitBitCastInst(BitCastInst &I) { |
| 3329 |
Check( |
3329 |
Check( |
| 3330 |
CastInst::castIsValid(Instruction::BitCast, I.getOperand(0), I.getType()), |
3330 |
CastInst::castIsValid(Instruction::BitCast, I.getOperand(0), I.getType()), |
| 3331 |
"Invalid bitcast", &I); |
3331 |
"Invalid bitcast", &I); |
| 3332 |
visitInstruction(I); |
3332 |
visitInstruction(I); |
| 3333 |
} |
3333 |
} |
| 3334 |
|
3334 |
|
| 3335 |
void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) { |
3335 |
void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) { |
| 3336 |
Type *SrcTy = I.getOperand(0)->getType(); |
3336 |
Type *SrcTy = I.getOperand(0)->getType(); |
| 3337 |
Type *DestTy = I.getType(); |
3337 |
Type *DestTy = I.getType(); |
| 3338 |
|
3338 |
|
| 3339 |
Check(SrcTy->isPtrOrPtrVectorTy(), "AddrSpaceCast source must be a pointer", |
3339 |
Check(SrcTy->isPtrOrPtrVectorTy(), "AddrSpaceCast source must be a pointer", |
| 3340 |
&I); |
3340 |
&I); |
| 3341 |
Check(DestTy->isPtrOrPtrVectorTy(), "AddrSpaceCast result must be a pointer", |
3341 |
Check(DestTy->isPtrOrPtrVectorTy(), "AddrSpaceCast result must be a pointer", |
| 3342 |
&I); |
3342 |
&I); |
| 3343 |
Check(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(), |
3343 |
Check(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(), |
| 3344 |
"AddrSpaceCast must be between different address spaces", &I); |
3344 |
"AddrSpaceCast must be between different address spaces", &I); |
| 3345 |
if (auto *SrcVTy = dyn_cast(SrcTy)) |
3345 |
if (auto *SrcVTy = dyn_cast(SrcTy)) |
| 3346 |
Check(SrcVTy->getElementCount() == |
3346 |
Check(SrcVTy->getElementCount() == |
| 3347 |
cast(DestTy)->getElementCount(), |
3347 |
cast(DestTy)->getElementCount(), |
| 3348 |
"AddrSpaceCast vector pointer number of elements mismatch", &I); |
3348 |
"AddrSpaceCast vector pointer number of elements mismatch", &I); |
| 3349 |
visitInstruction(I); |
3349 |
visitInstruction(I); |
| 3350 |
} |
3350 |
} |
| 3351 |
|
3351 |
|
| 3352 |
/// visitPHINode - Ensure that a PHI node is well formed. |
3352 |
/// visitPHINode - Ensure that a PHI node is well formed. |
| 3353 |
/// |
3353 |
/// |
| 3354 |
void Verifier::visitPHINode(PHINode &PN) { |
3354 |
void Verifier::visitPHINode(PHINode &PN) { |
| 3355 |
// Ensure that the PHI nodes are all grouped together at the top of the block. |
3355 |
// Ensure that the PHI nodes are all grouped together at the top of the block. |
| 3356 |
// This can be tested by checking whether the instruction before this is |
3356 |
// This can be tested by checking whether the instruction before this is |
| 3357 |
// either nonexistent (because this is begin()) or is a PHI node. If not, |
3357 |
// either nonexistent (because this is begin()) or is a PHI node. If not, |
| 3358 |
// then there is some other instruction before a PHI. |
3358 |
// then there is some other instruction before a PHI. |
| 3359 |
Check(&PN == &PN.getParent()->front() || |
3359 |
Check(&PN == &PN.getParent()->front() || |
| 3360 |
isa(--BasicBlock::iterator(&PN)), |
3360 |
isa(--BasicBlock::iterator(&PN)), |
| 3361 |
"PHI nodes not grouped at top of basic block!", &PN, PN.getParent()); |
3361 |
"PHI nodes not grouped at top of basic block!", &PN, PN.getParent()); |
| 3362 |
|
3362 |
|
| 3363 |
// Check that a PHI doesn't yield a Token. |
3363 |
// Check that a PHI doesn't yield a Token. |
| 3364 |
Check(!PN.getType()->isTokenTy(), "PHI nodes cannot have token type!"); |
3364 |
Check(!PN.getType()->isTokenTy(), "PHI nodes cannot have token type!"); |
| 3365 |
|
3365 |
|
| 3366 |
// Check that all of the values of the PHI node have the same type as the |
3366 |
// Check that all of the values of the PHI node have the same type as the |
| 3367 |
// result, and that the incoming blocks are really basic blocks. |
3367 |
// result, and that the incoming blocks are really basic blocks. |
| 3368 |
for (Value *IncValue : PN.incoming_values()) { |
3368 |
for (Value *IncValue : PN.incoming_values()) { |
| 3369 |
Check(PN.getType() == IncValue->getType(), |
3369 |
Check(PN.getType() == IncValue->getType(), |
| 3370 |
"PHI node operands are not the same type as the result!", &PN); |
3370 |
"PHI node operands are not the same type as the result!", &PN); |
| 3371 |
} |
3371 |
} |
| 3372 |
|
3372 |
|
| 3373 |
// All other PHI node constraints are checked in the visitBasicBlock method. |
3373 |
// All other PHI node constraints are checked in the visitBasicBlock method. |
| 3374 |
|
3374 |
|
| 3375 |
visitInstruction(PN); |
3375 |
visitInstruction(PN); |
| 3376 |
} |
3376 |
} |
| 3377 |
|
3377 |
|
| 3378 |
static bool isControlledConvergent(const CallBase &Call) { |
3378 |
static bool isControlledConvergent(const CallBase &Call) { |
| 3379 |
if (Call.getOperandBundle(LLVMContext::OB_convergencectrl)) |
3379 |
if (Call.getOperandBundle(LLVMContext::OB_convergencectrl)) |
| 3380 |
return true; |
3380 |
return true; |
| 3381 |
if (const auto *F = dyn_cast(Call.getCalledOperand())) { |
3381 |
if (const auto *F = dyn_cast(Call.getCalledOperand())) { |
| 3382 |
switch (F->getIntrinsicID()) { |
3382 |
switch (F->getIntrinsicID()) { |
| 3383 |
case Intrinsic::experimental_convergence_anchor: |
3383 |
case Intrinsic::experimental_convergence_anchor: |
| 3384 |
case Intrinsic::experimental_convergence_entry: |
3384 |
case Intrinsic::experimental_convergence_entry: |
| 3385 |
case Intrinsic::experimental_convergence_loop: |
3385 |
case Intrinsic::experimental_convergence_loop: |
| 3386 |
return true; |
3386 |
return true; |
| 3387 |
} |
3387 |
} |
| 3388 |
} |
3388 |
} |
| 3389 |
return false; |
3389 |
return false; |
| 3390 |
} |
3390 |
} |
| 3391 |
|
3391 |
|
| 3392 |
void Verifier::visitCallBase(CallBase &Call) { |
3392 |
void Verifier::visitCallBase(CallBase &Call) { |
| 3393 |
Check(Call.getCalledOperand()->getType()->isPointerTy(), |
3393 |
Check(Call.getCalledOperand()->getType()->isPointerTy(), |
| 3394 |
"Called function must be a pointer!", Call); |
3394 |
"Called function must be a pointer!", Call); |
| 3395 |
FunctionType *FTy = Call.getFunctionType(); |
3395 |
FunctionType *FTy = Call.getFunctionType(); |
| 3396 |
|
3396 |
|
| 3397 |
// Verify that the correct number of arguments are being passed |
3397 |
// Verify that the correct number of arguments are being passed |
| 3398 |
if (FTy->isVarArg()) |
3398 |
if (FTy->isVarArg()) |
| 3399 |
Check(Call.arg_size() >= FTy->getNumParams(), |
3399 |
Check(Call.arg_size() >= FTy->getNumParams(), |
| 3400 |
"Called function requires more parameters than were provided!", Call); |
3400 |
"Called function requires more parameters than were provided!", Call); |
| 3401 |
else |
3401 |
else |
| 3402 |
Check(Call.arg_size() == FTy->getNumParams(), |
3402 |
Check(Call.arg_size() == FTy->getNumParams(), |
| 3403 |
"Incorrect number of arguments passed to called function!", Call); |
3403 |
"Incorrect number of arguments passed to called function!", Call); |
| 3404 |
|
3404 |
|
| 3405 |
// Verify that all arguments to the call match the function type. |
3405 |
// Verify that all arguments to the call match the function type. |
| 3406 |
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) |
3406 |
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) |
| 3407 |
Check(Call.getArgOperand(i)->getType() == FTy->getParamType(i), |
3407 |
Check(Call.getArgOperand(i)->getType() == FTy->getParamType(i), |
| 3408 |
"Call parameter type does not match function signature!", |
3408 |
"Call parameter type does not match function signature!", |
| 3409 |
Call.getArgOperand(i), FTy->getParamType(i), Call); |
3409 |
Call.getArgOperand(i), FTy->getParamType(i), Call); |
| 3410 |
|
3410 |
|
| 3411 |
AttributeList Attrs = Call.getAttributes(); |
3411 |
AttributeList Attrs = Call.getAttributes(); |
| 3412 |
|
3412 |
|
| 3413 |
Check(verifyAttributeCount(Attrs, Call.arg_size()), |
3413 |
Check(verifyAttributeCount(Attrs, Call.arg_size()), |
| 3414 |
"Attribute after last parameter!", Call); |
3414 |
"Attribute after last parameter!", Call); |
| 3415 |
|
3415 |
|
| 3416 |
Function *Callee = |
3416 |
Function *Callee = |
| 3417 |
dyn_cast(Call.getCalledOperand()->stripPointerCasts()); |
3417 |
dyn_cast(Call.getCalledOperand()->stripPointerCasts()); |
| 3418 |
bool IsIntrinsic = Callee && Callee->isIntrinsic(); |
3418 |
bool IsIntrinsic = Callee && Callee->isIntrinsic(); |
| 3419 |
if (IsIntrinsic) |
3419 |
if (IsIntrinsic) |
| 3420 |
Check(Callee->getValueType() == FTy, |
3420 |
Check(Callee->getValueType() == FTy, |
| 3421 |
"Intrinsic called with incompatible signature", Call); |
3421 |
"Intrinsic called with incompatible signature", Call); |
| 3422 |
|
3422 |
|
| 3423 |
// Disallow calls to functions with the amdgpu_cs_chain[_preserve] calling |
3423 |
// Disallow calls to functions with the amdgpu_cs_chain[_preserve] calling |
| 3424 |
// convention. |
3424 |
// convention. |
| 3425 |
auto CC = Call.getCallingConv(); |
3425 |
auto CC = Call.getCallingConv(); |
| 3426 |
Check(CC != CallingConv::AMDGPU_CS_Chain && |
3426 |
Check(CC != CallingConv::AMDGPU_CS_Chain && |
| 3427 |
CC != CallingConv::AMDGPU_CS_ChainPreserve, |
3427 |
CC != CallingConv::AMDGPU_CS_ChainPreserve, |
| 3428 |
"Direct calls to amdgpu_cs_chain/amdgpu_cs_chain_preserve functions " |
3428 |
"Direct calls to amdgpu_cs_chain/amdgpu_cs_chain_preserve functions " |
| 3429 |
"not allowed. Please use the @llvm.amdgpu.cs.chain intrinsic instead.", |
3429 |
"not allowed. Please use the @llvm.amdgpu.cs.chain intrinsic instead.", |
| 3430 |
Call); |
3430 |
Call); |
| 3431 |
|
3431 |
|
| 3432 |
auto VerifyTypeAlign = [&](Type *Ty, const Twine &Message) { |
3432 |
auto VerifyTypeAlign = [&](Type *Ty, const Twine &Message) { |
| 3433 |
if (!Ty->isSized()) |
3433 |
if (!Ty->isSized()) |
| 3434 |
return; |
3434 |
return; |
| 3435 |
Align ABIAlign = DL.getABITypeAlign(Ty); |
3435 |
Align ABIAlign = DL.getABITypeAlign(Ty); |
| 3436 |
Align MaxAlign(ParamMaxAlignment); |
3436 |
Align MaxAlign(ParamMaxAlignment); |
| 3437 |
Check(ABIAlign <= MaxAlign, |
3437 |
Check(ABIAlign <= MaxAlign, |
| 3438 |
"Incorrect alignment of " + Message + " to called function!", Call); |
3438 |
"Incorrect alignment of " + Message + " to called function!", Call); |
| 3439 |
}; |
3439 |
}; |
| 3440 |
|
3440 |
|
| 3441 |
if (!IsIntrinsic) { |
3441 |
if (!IsIntrinsic) { |
| 3442 |
VerifyTypeAlign(FTy->getReturnType(), "return type"); |
3442 |
VerifyTypeAlign(FTy->getReturnType(), "return type"); |
| 3443 |
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) { |
3443 |
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) { |
| 3444 |
Type *Ty = FTy->getParamType(i); |
3444 |
Type *Ty = FTy->getParamType(i); |
| 3445 |
VerifyTypeAlign(Ty, "argument passed"); |
3445 |
VerifyTypeAlign(Ty, "argument passed"); |
| 3446 |
} |
3446 |
} |
| 3447 |
} |
3447 |
} |
| 3448 |
|
3448 |
|
| 3449 |
if (Attrs.hasFnAttr(Attribute::Speculatable)) { |
3449 |
if (Attrs.hasFnAttr(Attribute::Speculatable)) { |
| 3450 |
// Don't allow speculatable on call sites, unless the underlying function |
3450 |
// Don't allow speculatable on call sites, unless the underlying function |
| 3451 |
// declaration is also speculatable. |
3451 |
// declaration is also speculatable. |
| 3452 |
Check(Callee && Callee->isSpeculatable(), |
3452 |
Check(Callee && Callee->isSpeculatable(), |
| 3453 |
"speculatable attribute may not apply to call sites", Call); |
3453 |
"speculatable attribute may not apply to call sites", Call); |
| 3454 |
} |
3454 |
} |
| 3455 |
|
3455 |
|
| 3456 |
if (Attrs.hasFnAttr(Attribute::Preallocated)) { |
3456 |
if (Attrs.hasFnAttr(Attribute::Preallocated)) { |
| 3457 |
Check(Call.getCalledFunction()->getIntrinsicID() == |
3457 |
Check(Call.getCalledFunction()->getIntrinsicID() == |
| 3458 |
Intrinsic::call_preallocated_arg, |
3458 |
Intrinsic::call_preallocated_arg, |
| 3459 |
"preallocated as a call site attribute can only be on " |
3459 |
"preallocated as a call site attribute can only be on " |
| 3460 |
"llvm.call.preallocated.arg"); |
3460 |
"llvm.call.preallocated.arg"); |
| 3461 |
} |
3461 |
} |
| 3462 |
|
3462 |
|
| 3463 |
// Verify call attributes. |
3463 |
// Verify call attributes. |
| 3464 |
verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic, Call.isInlineAsm()); |
3464 |
verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic, Call.isInlineAsm()); |
| 3465 |
|
3465 |
|
| 3466 |
// Conservatively check the inalloca argument. |
3466 |
// Conservatively check the inalloca argument. |
| 3467 |
// We have a bug if we can find that there is an underlying alloca without |
3467 |
// We have a bug if we can find that there is an underlying alloca without |
| 3468 |
// inalloca. |
3468 |
// inalloca. |
| 3469 |
if (Call.hasInAllocaArgument()) { |
3469 |
if (Call.hasInAllocaArgument()) { |
| 3470 |
Value *InAllocaArg = Call.getArgOperand(FTy->getNumParams() - 1); |
3470 |
Value *InAllocaArg = Call.getArgOperand(FTy->getNumParams() - 1); |
| 3471 |
if (auto AI = dyn_cast(InAllocaArg->stripInBoundsOffsets())) |
3471 |
if (auto AI = dyn_cast(InAllocaArg->stripInBoundsOffsets())) |
| 3472 |
Check(AI->isUsedWithInAlloca(), |
3472 |
Check(AI->isUsedWithInAlloca(), |
| 3473 |
"inalloca argument for call has mismatched alloca", AI, Call); |
3473 |
"inalloca argument for call has mismatched alloca", AI, Call); |
| 3474 |
} |
3474 |
} |
| 3475 |
|
3475 |
|
| 3476 |
// For each argument of the callsite, if it has the swifterror argument, |
3476 |
// For each argument of the callsite, if it has the swifterror argument, |
| 3477 |
// make sure the underlying alloca/parameter it comes from has a swifterror as |
3477 |
// make sure the underlying alloca/parameter it comes from has a swifterror as |
| 3478 |
// well. |
3478 |
// well. |
| 3479 |
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) { |
3479 |
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) { |
| 3480 |
if (Call.paramHasAttr(i, Attribute::SwiftError)) { |
3480 |
if (Call.paramHasAttr(i, Attribute::SwiftError)) { |
| 3481 |
Value *SwiftErrorArg = Call.getArgOperand(i); |
3481 |
Value *SwiftErrorArg = Call.getArgOperand(i); |
| 3482 |
if (auto AI = dyn_cast(SwiftErrorArg->stripInBoundsOffsets())) { |
3482 |
if (auto AI = dyn_cast(SwiftErrorArg->stripInBoundsOffsets())) { |
| 3483 |
Check(AI->isSwiftError(), |
3483 |
Check(AI->isSwiftError(), |
| 3484 |
"swifterror argument for call has mismatched alloca", AI, Call); |
3484 |
"swifterror argument for call has mismatched alloca", AI, Call); |
| 3485 |
continue; |
3485 |
continue; |
| 3486 |
} |
3486 |
} |
| 3487 |
auto ArgI = dyn_cast(SwiftErrorArg); |
3487 |
auto ArgI = dyn_cast(SwiftErrorArg); |
| 3488 |
Check(ArgI, "swifterror argument should come from an alloca or parameter", |
3488 |
Check(ArgI, "swifterror argument should come from an alloca or parameter", |
| 3489 |
SwiftErrorArg, Call); |
3489 |
SwiftErrorArg, Call); |
| 3490 |
Check(ArgI->hasSwiftErrorAttr(), |
3490 |
Check(ArgI->hasSwiftErrorAttr(), |
| 3491 |
"swifterror argument for call has mismatched parameter", ArgI, |
3491 |
"swifterror argument for call has mismatched parameter", ArgI, |
| 3492 |
Call); |
3492 |
Call); |
| 3493 |
} |
3493 |
} |
| 3494 |
|
3494 |
|
| 3495 |
if (Attrs.hasParamAttr(i, Attribute::ImmArg)) { |
3495 |
if (Attrs.hasParamAttr(i, Attribute::ImmArg)) { |
| 3496 |
// Don't allow immarg on call sites, unless the underlying declaration |
3496 |
// Don't allow immarg on call sites, unless the underlying declaration |
| 3497 |
// also has the matching immarg. |
3497 |
// also has the matching immarg. |
| 3498 |
Check(Callee && Callee->hasParamAttribute(i, Attribute::ImmArg), |
3498 |
Check(Callee && Callee->hasParamAttribute(i, Attribute::ImmArg), |
| 3499 |
"immarg may not apply only to call sites", Call.getArgOperand(i), |
3499 |
"immarg may not apply only to call sites", Call.getArgOperand(i), |
| 3500 |
Call); |
3500 |
Call); |
| 3501 |
} |
3501 |
} |
| 3502 |
|
3502 |
|
| 3503 |
if (Call.paramHasAttr(i, Attribute::ImmArg)) { |
3503 |
if (Call.paramHasAttr(i, Attribute::ImmArg)) { |
| 3504 |
Value *ArgVal = Call.getArgOperand(i); |
3504 |
Value *ArgVal = Call.getArgOperand(i); |
| 3505 |
Check(isa(ArgVal) || isa(ArgVal), |
3505 |
Check(isa(ArgVal) || isa(ArgVal), |
| 3506 |
"immarg operand has non-immediate parameter", ArgVal, Call); |
3506 |
"immarg operand has non-immediate parameter", ArgVal, Call); |
| 3507 |
} |
3507 |
} |
| 3508 |
|
3508 |
|
| 3509 |
if (Call.paramHasAttr(i, Attribute::Preallocated)) { |
3509 |
if (Call.paramHasAttr(i, Attribute::Preallocated)) { |
| 3510 |
Value *ArgVal = Call.getArgOperand(i); |
3510 |
Value *ArgVal = Call.getArgOperand(i); |
| 3511 |
bool hasOB = |
3511 |
bool hasOB = |
| 3512 |
Call.countOperandBundlesOfType(LLVMContext::OB_preallocated) != 0; |
3512 |
Call.countOperandBundlesOfType(LLVMContext::OB_preallocated) != 0; |
| 3513 |
bool isMustTail = Call.isMustTailCall(); |
3513 |
bool isMustTail = Call.isMustTailCall(); |
| 3514 |
Check(hasOB != isMustTail, |
3514 |
Check(hasOB != isMustTail, |
| 3515 |
"preallocated operand either requires a preallocated bundle or " |
3515 |
"preallocated operand either requires a preallocated bundle or " |
| 3516 |
"the call to be musttail (but not both)", |
3516 |
"the call to be musttail (but not both)", |
| 3517 |
ArgVal, Call); |
3517 |
ArgVal, Call); |
| 3518 |
} |
3518 |
} |
| 3519 |
} |
3519 |
} |
| 3520 |
|
3520 |
|
| 3521 |
if (FTy->isVarArg()) { |
3521 |
if (FTy->isVarArg()) { |
| 3522 |
// FIXME? is 'nest' even legal here? |
3522 |
// FIXME? is 'nest' even legal here? |
| 3523 |
bool SawNest = false; |
3523 |
bool SawNest = false; |
| 3524 |
bool SawReturned = false; |
3524 |
bool SawReturned = false; |
| 3525 |
|
3525 |
|
| 3526 |
for (unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) { |
3526 |
for (unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) { |
| 3527 |
if (Attrs.hasParamAttr(Idx, Attribute::Nest)) |
3527 |
if (Attrs.hasParamAttr(Idx, Attribute::Nest)) |
| 3528 |
SawNest = true; |
3528 |
SawNest = true; |
| 3529 |
if (Attrs.hasParamAttr(Idx, Attribute::Returned)) |
3529 |
if (Attrs.hasParamAttr(Idx, Attribute::Returned)) |
| 3530 |
SawReturned = true; |
3530 |
SawReturned = true; |
| 3531 |
} |
3531 |
} |
| 3532 |
|
3532 |
|
| 3533 |
// Check attributes on the varargs part. |
3533 |
// Check attributes on the varargs part. |
| 3534 |
for (unsigned Idx = FTy->getNumParams(); Idx < Call.arg_size(); ++Idx) { |
3534 |
for (unsigned Idx = FTy->getNumParams(); Idx < Call.arg_size(); ++Idx) { |
| 3535 |
Type *Ty = Call.getArgOperand(Idx)->getType(); |
3535 |
Type *Ty = Call.getArgOperand(Idx)->getType(); |
| 3536 |
AttributeSet ArgAttrs = Attrs.getParamAttrs(Idx); |
3536 |
AttributeSet ArgAttrs = Attrs.getParamAttrs(Idx); |
| 3537 |
verifyParameterAttrs(ArgAttrs, Ty, &Call); |
3537 |
verifyParameterAttrs(ArgAttrs, Ty, &Call); |
| 3538 |
|
3538 |
|
| 3539 |
if (ArgAttrs.hasAttribute(Attribute::Nest)) { |
3539 |
if (ArgAttrs.hasAttribute(Attribute::Nest)) { |
| 3540 |
Check(!SawNest, "More than one parameter has attribute nest!", Call); |
3540 |
Check(!SawNest, "More than one parameter has attribute nest!", Call); |
| 3541 |
SawNest = true; |
3541 |
SawNest = true; |
| 3542 |
} |
3542 |
} |
| 3543 |
|
3543 |
|
| 3544 |
if (ArgAttrs.hasAttribute(Attribute::Returned)) { |
3544 |
if (ArgAttrs.hasAttribute(Attribute::Returned)) { |
| 3545 |
Check(!SawReturned, "More than one parameter has attribute returned!", |
3545 |
Check(!SawReturned, "More than one parameter has attribute returned!", |
| 3546 |
Call); |
3546 |
Call); |
| 3547 |
Check(Ty->canLosslesslyBitCastTo(FTy->getReturnType()), |
3547 |
Check(Ty->canLosslesslyBitCastTo(FTy->getReturnType()), |
| 3548 |
"Incompatible argument and return types for 'returned' " |
3548 |
"Incompatible argument and return types for 'returned' " |
| 3549 |
"attribute", |
3549 |
"attribute", |
| 3550 |
Call); |
3550 |
Call); |
| 3551 |
SawReturned = true; |
3551 |
SawReturned = true; |
| 3552 |
} |
3552 |
} |
| 3553 |
|
3553 |
|
| 3554 |
// Statepoint intrinsic is vararg but the wrapped function may be not. |
3554 |
// Statepoint intrinsic is vararg but the wrapped function may be not. |
| 3555 |
// Allow sret here and check the wrapped function in verifyStatepoint. |
3555 |
// Allow sret here and check the wrapped function in verifyStatepoint. |
| 3556 |
if (!Call.getCalledFunction() || |
3556 |
if (!Call.getCalledFunction() || |
| 3557 |
Call.getCalledFunction()->getIntrinsicID() != |
3557 |
Call.getCalledFunction()->getIntrinsicID() != |
| 3558 |
Intrinsic::experimental_gc_statepoint) |
3558 |
Intrinsic::experimental_gc_statepoint) |
| 3559 |
Check(!ArgAttrs.hasAttribute(Attribute::StructRet), |
3559 |
Check(!ArgAttrs.hasAttribute(Attribute::StructRet), |
| 3560 |
"Attribute 'sret' cannot be used for vararg call arguments!", |
3560 |
"Attribute 'sret' cannot be used for vararg call arguments!", |
| 3561 |
Call); |
3561 |
Call); |
| 3562 |
|
3562 |
|
| 3563 |
if (ArgAttrs.hasAttribute(Attribute::InAlloca)) |
3563 |
if (ArgAttrs.hasAttribute(Attribute::InAlloca)) |
| 3564 |
Check(Idx == Call.arg_size() - 1, |
3564 |
Check(Idx == Call.arg_size() - 1, |
| 3565 |
"inalloca isn't on the last argument!", Call); |
3565 |
"inalloca isn't on the last argument!", Call); |
| 3566 |
} |
3566 |
} |
| 3567 |
} |
3567 |
} |
| 3568 |
|
3568 |
|
| 3569 |
// Verify that there's no metadata unless it's a direct call to an intrinsic. |
3569 |
// Verify that there's no metadata unless it's a direct call to an intrinsic. |
| 3570 |
if (!IsIntrinsic) { |
3570 |
if (!IsIntrinsic) { |
| 3571 |
for (Type *ParamTy : FTy->params()) { |
3571 |
for (Type *ParamTy : FTy->params()) { |
| 3572 |
Check(!ParamTy->isMetadataTy(), |
3572 |
Check(!ParamTy->isMetadataTy(), |
| 3573 |
"Function has metadata parameter but isn't an intrinsic", Call); |
3573 |
"Function has metadata parameter but isn't an intrinsic", Call); |
| 3574 |
Check(!ParamTy->isTokenTy(), |
3574 |
Check(!ParamTy->isTokenTy(), |
| 3575 |
"Function has token parameter but isn't an intrinsic", Call); |
3575 |
"Function has token parameter but isn't an intrinsic", Call); |
| 3576 |
} |
3576 |
} |
| 3577 |
} |
3577 |
} |
| 3578 |
|
3578 |
|
| 3579 |
// Verify that indirect calls don't return tokens. |
3579 |
// Verify that indirect calls don't return tokens. |
| 3580 |
if (!Call.getCalledFunction()) { |
3580 |
if (!Call.getCalledFunction()) { |
| 3581 |
Check(!FTy->getReturnType()->isTokenTy(), |
3581 |
Check(!FTy->getReturnType()->isTokenTy(), |
| 3582 |
"Return type cannot be token for indirect call!"); |
3582 |
"Return type cannot be token for indirect call!"); |
| 3583 |
Check(!FTy->getReturnType()->isX86_AMXTy(), |
3583 |
Check(!FTy->getReturnType()->isX86_AMXTy(), |
| 3584 |
"Return type cannot be x86_amx for indirect call!"); |
3584 |
"Return type cannot be x86_amx for indirect call!"); |
| 3585 |
} |
3585 |
} |
| 3586 |
|
3586 |
|
| 3587 |
if (Function *F = Call.getCalledFunction()) |
3587 |
if (Function *F = Call.getCalledFunction()) |
| 3588 |
if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) |
3588 |
if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) |
| 3589 |
visitIntrinsicCall(ID, Call); |
3589 |
visitIntrinsicCall(ID, Call); |
| 3590 |
|
3590 |
|
| 3591 |
// Verify that a callsite has at most one "deopt", at most one "funclet", at |
3591 |
// Verify that a callsite has at most one "deopt", at most one "funclet", at |
| 3592 |
// most one "gc-transition", at most one "cfguardtarget", at most one |
3592 |
// most one "gc-transition", at most one "cfguardtarget", at most one |
| 3593 |
// "preallocated" operand bundle, and at most one "ptrauth" operand bundle. |
3593 |
// "preallocated" operand bundle, and at most one "ptrauth" operand bundle. |
| 3594 |
bool FoundDeoptBundle = false, FoundFuncletBundle = false, |
3594 |
bool FoundDeoptBundle = false, FoundFuncletBundle = false, |
| 3595 |
FoundGCTransitionBundle = false, FoundCFGuardTargetBundle = false, |
3595 |
FoundGCTransitionBundle = false, FoundCFGuardTargetBundle = false, |
| 3596 |
FoundPreallocatedBundle = false, FoundGCLiveBundle = false, |
3596 |
FoundPreallocatedBundle = false, FoundGCLiveBundle = false, |
| 3597 |
FoundPtrauthBundle = false, FoundKCFIBundle = false, |
3597 |
FoundPtrauthBundle = false, FoundKCFIBundle = false, |
| 3598 |
FoundAttachedCallBundle = false; |
3598 |
FoundAttachedCallBundle = false; |
| 3599 |
for (unsigned i = 0, e = Call.getNumOperandBundles(); i < e; ++i) { |
3599 |
for (unsigned i = 0, e = Call.getNumOperandBundles(); i < e; ++i) { |
| 3600 |
OperandBundleUse BU = Call.getOperandBundleAt(i); |
3600 |
OperandBundleUse BU = Call.getOperandBundleAt(i); |
| 3601 |
uint32_t Tag = BU.getTagID(); |
3601 |
uint32_t Tag = BU.getTagID(); |
| 3602 |
if (Tag == LLVMContext::OB_deopt) { |
3602 |
if (Tag == LLVMContext::OB_deopt) { |
| 3603 |
Check(!FoundDeoptBundle, "Multiple deopt operand bundles", Call); |
3603 |
Check(!FoundDeoptBundle, "Multiple deopt operand bundles", Call); |
| 3604 |
FoundDeoptBundle = true; |
3604 |
FoundDeoptBundle = true; |
| 3605 |
} else if (Tag == LLVMContext::OB_gc_transition) { |
3605 |
} else if (Tag == LLVMContext::OB_gc_transition) { |
| 3606 |
Check(!FoundGCTransitionBundle, "Multiple gc-transition operand bundles", |
3606 |
Check(!FoundGCTransitionBundle, "Multiple gc-transition operand bundles", |
| 3607 |
Call); |
3607 |
Call); |
| 3608 |
FoundGCTransitionBundle = true; |
3608 |
FoundGCTransitionBundle = true; |
| 3609 |
} else if (Tag == LLVMContext::OB_funclet) { |
3609 |
} else if (Tag == LLVMContext::OB_funclet) { |
| 3610 |
Check(!FoundFuncletBundle, "Multiple funclet operand bundles", Call); |
3610 |
Check(!FoundFuncletBundle, "Multiple funclet operand bundles", Call); |
| 3611 |
FoundFuncletBundle = true; |
3611 |
FoundFuncletBundle = true; |
| 3612 |
Check(BU.Inputs.size() == 1, |
3612 |
Check(BU.Inputs.size() == 1, |
| 3613 |
"Expected exactly one funclet bundle operand", Call); |
3613 |
"Expected exactly one funclet bundle operand", Call); |
| 3614 |
Check(isa(BU.Inputs.front()), |
3614 |
Check(isa(BU.Inputs.front()), |
| 3615 |
"Funclet bundle operands should correspond to a FuncletPadInst", |
3615 |
"Funclet bundle operands should correspond to a FuncletPadInst", |
| 3616 |
Call); |
3616 |
Call); |
| 3617 |
} else if (Tag == LLVMContext::OB_cfguardtarget) { |
3617 |
} else if (Tag == LLVMContext::OB_cfguardtarget) { |
| 3618 |
Check(!FoundCFGuardTargetBundle, "Multiple CFGuardTarget operand bundles", |
3618 |
Check(!FoundCFGuardTargetBundle, "Multiple CFGuardTarget operand bundles", |
| 3619 |
Call); |
3619 |
Call); |
| 3620 |
FoundCFGuardTargetBundle = true; |
3620 |
FoundCFGuardTargetBundle = true; |
| 3621 |
Check(BU.Inputs.size() == 1, |
3621 |
Check(BU.Inputs.size() == 1, |
| 3622 |
"Expected exactly one cfguardtarget bundle operand", Call); |
3622 |
"Expected exactly one cfguardtarget bundle operand", Call); |
| 3623 |
} else if (Tag == LLVMContext::OB_ptrauth) { |
3623 |
} else if (Tag == LLVMContext::OB_ptrauth) { |
| 3624 |
Check(!FoundPtrauthBundle, "Multiple ptrauth operand bundles", Call); |
3624 |
Check(!FoundPtrauthBundle, "Multiple ptrauth operand bundles", Call); |
| 3625 |
FoundPtrauthBundle = true; |
3625 |
FoundPtrauthBundle = true; |
| 3626 |
Check(BU.Inputs.size() == 2, |
3626 |
Check(BU.Inputs.size() == 2, |
| 3627 |
"Expected exactly two ptrauth bundle operands", Call); |
3627 |
"Expected exactly two ptrauth bundle operands", Call); |
| 3628 |
Check(isa(BU.Inputs[0]) && |
3628 |
Check(isa(BU.Inputs[0]) && |
| 3629 |
BU.Inputs[0]->getType()->isIntegerTy(32), |
3629 |
BU.Inputs[0]->getType()->isIntegerTy(32), |
| 3630 |
"Ptrauth bundle key operand must be an i32 constant", Call); |
3630 |
"Ptrauth bundle key operand must be an i32 constant", Call); |
| 3631 |
Check(BU.Inputs[1]->getType()->isIntegerTy(64), |
3631 |
Check(BU.Inputs[1]->getType()->isIntegerTy(64), |
| 3632 |
"Ptrauth bundle discriminator operand must be an i64", Call); |
3632 |
"Ptrauth bundle discriminator operand must be an i64", Call); |
| 3633 |
} else if (Tag == LLVMContext::OB_kcfi) { |
3633 |
} else if (Tag == LLVMContext::OB_kcfi) { |
| 3634 |
Check(!FoundKCFIBundle, "Multiple kcfi operand bundles", Call); |
3634 |
Check(!FoundKCFIBundle, "Multiple kcfi operand bundles", Call); |
| 3635 |
FoundKCFIBundle = true; |
3635 |
FoundKCFIBundle = true; |
| 3636 |
Check(BU.Inputs.size() == 1, "Expected exactly one kcfi bundle operand", |
3636 |
Check(BU.Inputs.size() == 1, "Expected exactly one kcfi bundle operand", |
| 3637 |
Call); |
3637 |
Call); |
| 3638 |
Check(isa(BU.Inputs[0]) && |
3638 |
Check(isa(BU.Inputs[0]) && |
| 3639 |
BU.Inputs[0]->getType()->isIntegerTy(32), |
3639 |
BU.Inputs[0]->getType()->isIntegerTy(32), |
| 3640 |
"Kcfi bundle operand must be an i32 constant", Call); |
3640 |
"Kcfi bundle operand must be an i32 constant", Call); |
| 3641 |
} else if (Tag == LLVMContext::OB_preallocated) { |
3641 |
} else if (Tag == LLVMContext::OB_preallocated) { |
| 3642 |
Check(!FoundPreallocatedBundle, "Multiple preallocated operand bundles", |
3642 |
Check(!FoundPreallocatedBundle, "Multiple preallocated operand bundles", |
| 3643 |
Call); |
3643 |
Call); |
| 3644 |
FoundPreallocatedBundle = true; |
3644 |
FoundPreallocatedBundle = true; |
| 3645 |
Check(BU.Inputs.size() == 1, |
3645 |
Check(BU.Inputs.size() == 1, |
| 3646 |
"Expected exactly one preallocated bundle operand", Call); |
3646 |
"Expected exactly one preallocated bundle operand", Call); |
| 3647 |
auto Input = dyn_cast(BU.Inputs.front()); |
3647 |
auto Input = dyn_cast(BU.Inputs.front()); |
| 3648 |
Check(Input && |
3648 |
Check(Input && |
| 3649 |
Input->getIntrinsicID() == Intrinsic::call_preallocated_setup, |
3649 |
Input->getIntrinsicID() == Intrinsic::call_preallocated_setup, |
| 3650 |
"\"preallocated\" argument must be a token from " |
3650 |
"\"preallocated\" argument must be a token from " |
| 3651 |
"llvm.call.preallocated.setup", |
3651 |
"llvm.call.preallocated.setup", |
| 3652 |
Call); |
3652 |
Call); |
| 3653 |
} else if (Tag == LLVMContext::OB_gc_live) { |
3653 |
} else if (Tag == LLVMContext::OB_gc_live) { |
| 3654 |
Check(!FoundGCLiveBundle, "Multiple gc-live operand bundles", Call); |
3654 |
Check(!FoundGCLiveBundle, "Multiple gc-live operand bundles", Call); |
| 3655 |
FoundGCLiveBundle = true; |
3655 |
FoundGCLiveBundle = true; |
| 3656 |
} else if (Tag == LLVMContext::OB_clang_arc_attachedcall) { |
3656 |
} else if (Tag == LLVMContext::OB_clang_arc_attachedcall) { |
| 3657 |
Check(!FoundAttachedCallBundle, |
3657 |
Check(!FoundAttachedCallBundle, |
| 3658 |
"Multiple \"clang.arc.attachedcall\" operand bundles", Call); |
3658 |
"Multiple \"clang.arc.attachedcall\" operand bundles", Call); |
| 3659 |
FoundAttachedCallBundle = true; |
3659 |
FoundAttachedCallBundle = true; |
| 3660 |
verifyAttachedCallBundle(Call, BU); |
3660 |
verifyAttachedCallBundle(Call, BU); |
| 3661 |
} |
3661 |
} |
| 3662 |
} |
3662 |
} |
| 3663 |
|
3663 |
|
| 3664 |
// Verify that callee and callsite agree on whether to use pointer auth. |
3664 |
// Verify that callee and callsite agree on whether to use pointer auth. |
| 3665 |
Check(!(Call.getCalledFunction() && FoundPtrauthBundle), |
3665 |
Check(!(Call.getCalledFunction() && FoundPtrauthBundle), |
| 3666 |
"Direct call cannot have a ptrauth bundle", Call); |
3666 |
"Direct call cannot have a ptrauth bundle", Call); |
| 3667 |
|
3667 |
|
| 3668 |
// Verify that each inlinable callsite of a debug-info-bearing function in a |
3668 |
// Verify that each inlinable callsite of a debug-info-bearing function in a |
| 3669 |
// debug-info-bearing function has a debug location attached to it. Failure to |
3669 |
// debug-info-bearing function has a debug location attached to it. Failure to |
| 3670 |
// do so causes assertion failures when the inliner sets up inline scope info |
3670 |
// do so causes assertion failures when the inliner sets up inline scope info |
| 3671 |
// (Interposable functions are not inlinable, neither are functions without |
3671 |
// (Interposable functions are not inlinable, neither are functions without |
| 3672 |
// definitions.) |
3672 |
// definitions.) |
| 3673 |
if (Call.getFunction()->getSubprogram() && Call.getCalledFunction() && |
3673 |
if (Call.getFunction()->getSubprogram() && Call.getCalledFunction() && |
| 3674 |
!Call.getCalledFunction()->isInterposable() && |
3674 |
!Call.getCalledFunction()->isInterposable() && |
| 3675 |
!Call.getCalledFunction()->isDeclaration() && |
3675 |
!Call.getCalledFunction()->isDeclaration() && |
| 3676 |
Call.getCalledFunction()->getSubprogram()) |
3676 |
Call.getCalledFunction()->getSubprogram()) |
| 3677 |
CheckDI(Call.getDebugLoc(), |
3677 |
CheckDI(Call.getDebugLoc(), |
| 3678 |
"inlinable function call in a function with " |
3678 |
"inlinable function call in a function with " |
| 3679 |
"debug info must have a !dbg location", |
3679 |
"debug info must have a !dbg location", |
| 3680 |
Call); |
3680 |
Call); |
| 3681 |
|
3681 |
|
| 3682 |
if (Call.isInlineAsm()) |
3682 |
if (Call.isInlineAsm()) |
| 3683 |
verifyInlineAsmCall(Call); |
3683 |
verifyInlineAsmCall(Call); |
| 3684 |
|
3684 |
|
| 3685 |
if (isControlledConvergent(Call)) { |
3685 |
if (isControlledConvergent(Call)) { |
| 3686 |
Check(Call.isConvergent(), |
3686 |
Check(Call.isConvergent(), |
| 3687 |
"Expected convergent attribute on a controlled convergent call.", |
3687 |
"Expected convergent attribute on a controlled convergent call.", |
| 3688 |
Call); |
3688 |
Call); |
| 3689 |
Check(ConvergenceKind != UncontrolledConvergence, |
3689 |
Check(ConvergenceKind != UncontrolledConvergence, |
| 3690 |
"Cannot mix controlled and uncontrolled convergence in the same " |
3690 |
"Cannot mix controlled and uncontrolled convergence in the same " |
| 3691 |
"function.", |
3691 |
"function.", |
| 3692 |
Call); |
3692 |
Call); |
| 3693 |
ConvergenceKind = ControlledConvergence; |
3693 |
ConvergenceKind = ControlledConvergence; |
| 3694 |
} else if (Call.isConvergent()) { |
3694 |
} else if (Call.isConvergent()) { |
| 3695 |
Check(ConvergenceKind != ControlledConvergence, |
3695 |
Check(ConvergenceKind != ControlledConvergence, |
| 3696 |
"Cannot mix controlled and uncontrolled convergence in the same " |
3696 |
"Cannot mix controlled and uncontrolled convergence in the same " |
| 3697 |
"function.", |
3697 |
"function.", |
| 3698 |
Call); |
3698 |
Call); |
| 3699 |
ConvergenceKind = UncontrolledConvergence; |
3699 |
ConvergenceKind = UncontrolledConvergence; |
| 3700 |
} |
3700 |
} |
| 3701 |
|
3701 |
|
| 3702 |
visitInstruction(Call); |
3702 |
visitInstruction(Call); |
| 3703 |
} |
3703 |
} |
| 3704 |
|
3704 |
|
| 3705 |
void Verifier::verifyTailCCMustTailAttrs(const AttrBuilder &Attrs, |
3705 |
void Verifier::verifyTailCCMustTailAttrs(const AttrBuilder &Attrs, |
| 3706 |
StringRef Context) { |
3706 |
StringRef Context) { |
| 3707 |
Check(!Attrs.contains(Attribute::InAlloca), |
3707 |
Check(!Attrs.contains(Attribute::InAlloca), |
| 3708 |
Twine("inalloca attribute not allowed in ") + Context); |
3708 |
Twine("inalloca attribute not allowed in ") + Context); |
| 3709 |
Check(!Attrs.contains(Attribute::InReg), |
3709 |
Check(!Attrs.contains(Attribute::InReg), |
| 3710 |
Twine("inreg attribute not allowed in ") + Context); |
3710 |
Twine("inreg attribute not allowed in ") + Context); |
| 3711 |
Check(!Attrs.contains(Attribute::SwiftError), |
3711 |
Check(!Attrs.contains(Attribute::SwiftError), |
| 3712 |
Twine("swifterror attribute not allowed in ") + Context); |
3712 |
Twine("swifterror attribute not allowed in ") + Context); |
| 3713 |
Check(!Attrs.contains(Attribute::Preallocated), |
3713 |
Check(!Attrs.contains(Attribute::Preallocated), |
| 3714 |
Twine("preallocated attribute not allowed in ") + Context); |
3714 |
Twine("preallocated attribute not allowed in ") + Context); |
| 3715 |
Check(!Attrs.contains(Attribute::ByRef), |
3715 |
Check(!Attrs.contains(Attribute::ByRef), |
| 3716 |
Twine("byref attribute not allowed in ") + Context); |
3716 |
Twine("byref attribute not allowed in ") + Context); |
| 3717 |
} |
3717 |
} |
| 3718 |
|
3718 |
|
| 3719 |
/// Two types are "congruent" if they are identical, or if they are both pointer |
3719 |
/// Two types are "congruent" if they are identical, or if they are both pointer |
| 3720 |
/// types with different pointee types and the same address space. |
3720 |
/// types with different pointee types and the same address space. |
| 3721 |
static bool isTypeCongruent(Type *L, Type *R) { |
3721 |
static bool isTypeCongruent(Type *L, Type *R) { |
| 3722 |
if (L == R) |
3722 |
if (L == R) |
| 3723 |
return true; |
3723 |
return true; |
| 3724 |
PointerType *PL = dyn_cast(L); |
3724 |
PointerType *PL = dyn_cast(L); |
| 3725 |
PointerType *PR = dyn_cast(R); |
3725 |
PointerType *PR = dyn_cast(R); |
| 3726 |
if (!PL || !PR) |
3726 |
if (!PL || !PR) |
| 3727 |
return false; |
3727 |
return false; |
| 3728 |
return PL->getAddressSpace() == PR->getAddressSpace(); |
3728 |
return PL->getAddressSpace() == PR->getAddressSpace(); |
| 3729 |
} |
3729 |
} |
| 3730 |
|
3730 |
|
| 3731 |
static AttrBuilder getParameterABIAttributes(LLVMContext& C, unsigned I, AttributeList Attrs) { |
3731 |
static AttrBuilder getParameterABIAttributes(LLVMContext& C, unsigned I, AttributeList Attrs) { |
| 3732 |
static const Attribute::AttrKind ABIAttrs[] = { |
3732 |
static const Attribute::AttrKind ABIAttrs[] = { |
| 3733 |
Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca, |
3733 |
Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca, |
| 3734 |
Attribute::InReg, Attribute::StackAlignment, Attribute::SwiftSelf, |
3734 |
Attribute::InReg, Attribute::StackAlignment, Attribute::SwiftSelf, |
| 3735 |
Attribute::SwiftAsync, Attribute::SwiftError, Attribute::Preallocated, |
3735 |
Attribute::SwiftAsync, Attribute::SwiftError, Attribute::Preallocated, |
| 3736 |
Attribute::ByRef}; |
3736 |
Attribute::ByRef}; |
| 3737 |
AttrBuilder Copy(C); |
3737 |
AttrBuilder Copy(C); |
| 3738 |
for (auto AK : ABIAttrs) { |
3738 |
for (auto AK : ABIAttrs) { |
| 3739 |
Attribute Attr = Attrs.getParamAttrs(I).getAttribute(AK); |
3739 |
Attribute Attr = Attrs.getParamAttrs(I).getAttribute(AK); |
| 3740 |
if (Attr.isValid()) |
3740 |
if (Attr.isValid()) |
| 3741 |
Copy.addAttribute(Attr); |
3741 |
Copy.addAttribute(Attr); |
| 3742 |
} |
3742 |
} |
| 3743 |
|
3743 |
|
| 3744 |
// `align` is ABI-affecting only in combination with `byval` or `byref`. |
3744 |
// `align` is ABI-affecting only in combination with `byval` or `byref`. |
| 3745 |
if (Attrs.hasParamAttr(I, Attribute::Alignment) && |
3745 |
if (Attrs.hasParamAttr(I, Attribute::Alignment) && |
| 3746 |
(Attrs.hasParamAttr(I, Attribute::ByVal) || |
3746 |
(Attrs.hasParamAttr(I, Attribute::ByVal) || |
| 3747 |
Attrs.hasParamAttr(I, Attribute::ByRef))) |
3747 |
Attrs.hasParamAttr(I, Attribute::ByRef))) |
| 3748 |
Copy.addAlignmentAttr(Attrs.getParamAlignment(I)); |
3748 |
Copy.addAlignmentAttr(Attrs.getParamAlignment(I)); |
| 3749 |
return Copy; |
3749 |
return Copy; |
| 3750 |
} |
3750 |
} |
| 3751 |
|
3751 |
|
| 3752 |
void Verifier::verifyMustTailCall(CallInst &CI) { |
3752 |
void Verifier::verifyMustTailCall(CallInst &CI) { |
| 3753 |
Check(!CI.isInlineAsm(), "cannot use musttail call with inline asm", &CI); |
3753 |
Check(!CI.isInlineAsm(), "cannot use musttail call with inline asm", &CI); |
| 3754 |
|
3754 |
|
| 3755 |
Function *F = CI.getParent()->getParent(); |
3755 |
Function *F = CI.getParent()->getParent(); |
| 3756 |
FunctionType *CallerTy = F->getFunctionType(); |
3756 |
FunctionType *CallerTy = F->getFunctionType(); |
| 3757 |
FunctionType *CalleeTy = CI.getFunctionType(); |
3757 |
FunctionType *CalleeTy = CI.getFunctionType(); |
| 3758 |
Check(CallerTy->isVarArg() == CalleeTy->isVarArg(), |
3758 |
Check(CallerTy->isVarArg() == CalleeTy->isVarArg(), |
| 3759 |
"cannot guarantee tail call due to mismatched varargs", &CI); |
3759 |
"cannot guarantee tail call due to mismatched varargs", &CI); |
| 3760 |
Check(isTypeCongruent(CallerTy->getReturnType(), CalleeTy->getReturnType()), |
3760 |
Check(isTypeCongruent(CallerTy->getReturnType(), CalleeTy->getReturnType()), |
| 3761 |
"cannot guarantee tail call due to mismatched return types", &CI); |
3761 |
"cannot guarantee tail call due to mismatched return types", &CI); |
| 3762 |
|
3762 |
|
| 3763 |
// - The calling conventions of the caller and callee must match. |
3763 |
// - The calling conventions of the caller and callee must match. |
| 3764 |
Check(F->getCallingConv() == CI.getCallingConv(), |
3764 |
Check(F->getCallingConv() == CI.getCallingConv(), |
| 3765 |
"cannot guarantee tail call due to mismatched calling conv", &CI); |
3765 |
"cannot guarantee tail call due to mismatched calling conv", &CI); |
| 3766 |
|
3766 |
|
| 3767 |
// - The call must immediately precede a :ref:`ret ` instruction, |
3767 |
// - The call must immediately precede a :ref:`ret ` instruction, |
| 3768 |
// or a pointer bitcast followed by a ret instruction. |
3768 |
// or a pointer bitcast followed by a ret instruction. |
| 3769 |
// - The ret instruction must return the (possibly bitcasted) value |
3769 |
// - The ret instruction must return the (possibly bitcasted) value |
| 3770 |
// produced by the call or void. |
3770 |
// produced by the call or void. |
| 3771 |
Value *RetVal = &CI; |
3771 |
Value *RetVal = &CI; |
| 3772 |
Instruction *Next = CI.getNextNode(); |
3772 |
Instruction *Next = CI.getNextNode(); |
| 3773 |
|
3773 |
|
| 3774 |
// Handle the optional bitcast. |
3774 |
// Handle the optional bitcast. |
| 3775 |
if (BitCastInst *BI = dyn_cast_or_null(Next)) { |
3775 |
if (BitCastInst *BI = dyn_cast_or_null(Next)) { |
| 3776 |
Check(BI->getOperand(0) == RetVal, |
3776 |
Check(BI->getOperand(0) == RetVal, |
| 3777 |
"bitcast following musttail call must use the call", BI); |
3777 |
"bitcast following musttail call must use the call", BI); |
| 3778 |
RetVal = BI; |
3778 |
RetVal = BI; |
| 3779 |
Next = BI->getNextNode(); |
3779 |
Next = BI->getNextNode(); |
| 3780 |
} |
3780 |
} |
| 3781 |
|
3781 |
|
| 3782 |
// Check the return. |
3782 |
// Check the return. |
| 3783 |
ReturnInst *Ret = dyn_cast_or_null(Next); |
3783 |
ReturnInst *Ret = dyn_cast_or_null(Next); |
| 3784 |
Check(Ret, "musttail call must precede a ret with an optional bitcast", &CI); |
3784 |
Check(Ret, "musttail call must precede a ret with an optional bitcast", &CI); |
| 3785 |
Check(!Ret->getReturnValue() || Ret->getReturnValue() == RetVal || |
3785 |
Check(!Ret->getReturnValue() || Ret->getReturnValue() == RetVal || |
| 3786 |
isa(Ret->getReturnValue()), |
3786 |
isa(Ret->getReturnValue()), |
| 3787 |
"musttail call result must be returned", Ret); |
3787 |
"musttail call result must be returned", Ret); |
| 3788 |
|
3788 |
|
| 3789 |
AttributeList CallerAttrs = F->getAttributes(); |
3789 |
AttributeList CallerAttrs = F->getAttributes(); |
| 3790 |
AttributeList CalleeAttrs = CI.getAttributes(); |
3790 |
AttributeList CalleeAttrs = CI.getAttributes(); |
| 3791 |
if (CI.getCallingConv() == CallingConv::SwiftTail || |
3791 |
if (CI.getCallingConv() == CallingConv::SwiftTail || |
| 3792 |
CI.getCallingConv() == CallingConv::Tail) { |
3792 |
CI.getCallingConv() == CallingConv::Tail) { |
| 3793 |
StringRef CCName = |
3793 |
StringRef CCName = |
| 3794 |
CI.getCallingConv() == CallingConv::Tail ? "tailcc" : "swifttailcc"; |
3794 |
CI.getCallingConv() == CallingConv::Tail ? "tailcc" : "swifttailcc"; |
| 3795 |
|
3795 |
|
| 3796 |
// - Only sret, byval, swiftself, and swiftasync ABI-impacting attributes |
3796 |
// - Only sret, byval, swiftself, and swiftasync ABI-impacting attributes |
| 3797 |
// are allowed in swifttailcc call |
3797 |
// are allowed in swifttailcc call |
| 3798 |
for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { |
3798 |
for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { |
| 3799 |
AttrBuilder ABIAttrs = getParameterABIAttributes(F->getContext(), I, CallerAttrs); |
3799 |
AttrBuilder ABIAttrs = getParameterABIAttributes(F->getContext(), I, CallerAttrs); |
| 3800 |
SmallString<32> Context{CCName, StringRef(" musttail caller")}; |
3800 |
SmallString<32> Context{CCName, StringRef(" musttail caller")}; |
| 3801 |
verifyTailCCMustTailAttrs(ABIAttrs, Context); |
3801 |
verifyTailCCMustTailAttrs(ABIAttrs, Context); |
| 3802 |
} |
3802 |
} |
| 3803 |
for (unsigned I = 0, E = CalleeTy->getNumParams(); I != E; ++I) { |
3803 |
for (unsigned I = 0, E = CalleeTy->getNumParams(); I != E; ++I) { |
| 3804 |
AttrBuilder ABIAttrs = getParameterABIAttributes(F->getContext(), I, CalleeAttrs); |
3804 |
AttrBuilder ABIAttrs = getParameterABIAttributes(F->getContext(), I, CalleeAttrs); |
| 3805 |
SmallString<32> Context{CCName, StringRef(" musttail callee")}; |
3805 |
SmallString<32> Context{CCName, StringRef(" musttail callee")}; |
| 3806 |
verifyTailCCMustTailAttrs(ABIAttrs, Context); |
3806 |
verifyTailCCMustTailAttrs(ABIAttrs, Context); |
| 3807 |
} |
3807 |
} |
| 3808 |
// - Varargs functions are not allowed |
3808 |
// - Varargs functions are not allowed |
| 3809 |
Check(!CallerTy->isVarArg(), Twine("cannot guarantee ") + CCName + |
3809 |
Check(!CallerTy->isVarArg(), Twine("cannot guarantee ") + CCName + |
| 3810 |
" tail call for varargs function"); |
3810 |
" tail call for varargs function"); |
| 3811 |
return; |
3811 |
return; |
| 3812 |
} |
3812 |
} |
| 3813 |
|
3813 |
|
| 3814 |
// - The caller and callee prototypes must match. Pointer types of |
3814 |
// - The caller and callee prototypes must match. Pointer types of |
| 3815 |
// parameters or return types may differ in pointee type, but not |
3815 |
// parameters or return types may differ in pointee type, but not |
| 3816 |
// address space. |
3816 |
// address space. |
| 3817 |
if (!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) { |
3817 |
if (!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) { |
| 3818 |
Check(CallerTy->getNumParams() == CalleeTy->getNumParams(), |
3818 |
Check(CallerTy->getNumParams() == CalleeTy->getNumParams(), |
| 3819 |
"cannot guarantee tail call due to mismatched parameter counts", &CI); |
3819 |
"cannot guarantee tail call due to mismatched parameter counts", &CI); |
| 3820 |
for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { |
3820 |
for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { |
| 3821 |
Check( |
3821 |
Check( |
| 3822 |
isTypeCongruent(CallerTy->getParamType(I), CalleeTy->getParamType(I)), |
3822 |
isTypeCongruent(CallerTy->getParamType(I), CalleeTy->getParamType(I)), |
| 3823 |
"cannot guarantee tail call due to mismatched parameter types", &CI); |
3823 |
"cannot guarantee tail call due to mismatched parameter types", &CI); |
| 3824 |
} |
3824 |
} |
| 3825 |
} |
3825 |
} |
| 3826 |
|
3826 |
|
| 3827 |
// - All ABI-impacting function attributes, such as sret, byval, inreg, |
3827 |
// - All ABI-impacting function attributes, such as sret, byval, inreg, |
| 3828 |
// returned, preallocated, and inalloca, must match. |
3828 |
// returned, preallocated, and inalloca, must match. |
| 3829 |
for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { |
3829 |
for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { |
| 3830 |
AttrBuilder CallerABIAttrs = getParameterABIAttributes(F->getContext(), I, CallerAttrs); |
3830 |
AttrBuilder CallerABIAttrs = getParameterABIAttributes(F->getContext(), I, CallerAttrs); |
| 3831 |
AttrBuilder CalleeABIAttrs = getParameterABIAttributes(F->getContext(), I, CalleeAttrs); |
3831 |
AttrBuilder CalleeABIAttrs = getParameterABIAttributes(F->getContext(), I, CalleeAttrs); |
| 3832 |
Check(CallerABIAttrs == CalleeABIAttrs, |
3832 |
Check(CallerABIAttrs == CalleeABIAttrs, |
| 3833 |
"cannot guarantee tail call due to mismatched ABI impacting " |
3833 |
"cannot guarantee tail call due to mismatched ABI impacting " |
| 3834 |
"function attributes", |
3834 |
"function attributes", |
| 3835 |
&CI, CI.getOperand(I)); |
3835 |
&CI, CI.getOperand(I)); |
| 3836 |
} |
3836 |
} |
| 3837 |
} |
3837 |
} |
| 3838 |
|
3838 |
|
| 3839 |
void Verifier::visitCallInst(CallInst &CI) { |
3839 |
void Verifier::visitCallInst(CallInst &CI) { |
| 3840 |
visitCallBase(CI); |
3840 |
visitCallBase(CI); |
| 3841 |
|
3841 |
|
| 3842 |
if (CI.isMustTailCall()) |
3842 |
if (CI.isMustTailCall()) |
| 3843 |
verifyMustTailCall(CI); |
3843 |
verifyMustTailCall(CI); |
| 3844 |
} |
3844 |
} |
| 3845 |
|
3845 |
|
| 3846 |
void Verifier::visitInvokeInst(InvokeInst &II) { |
3846 |
void Verifier::visitInvokeInst(InvokeInst &II) { |
| 3847 |
visitCallBase(II); |
3847 |
visitCallBase(II); |
| 3848 |
|
3848 |
|
| 3849 |
// Verify that the first non-PHI instruction of the unwind destination is an |
3849 |
// Verify that the first non-PHI instruction of the unwind destination is an |
| 3850 |
// exception handling instruction. |
3850 |
// exception handling instruction. |
| 3851 |
Check( |
3851 |
Check( |
| 3852 |
II.getUnwindDest()->isEHPad(), |
3852 |
II.getUnwindDest()->isEHPad(), |
| 3853 |
"The unwind destination does not have an exception handling instruction!", |
3853 |
"The unwind destination does not have an exception handling instruction!", |
| 3854 |
&II); |
3854 |
&II); |
| 3855 |
|
3855 |
|
| 3856 |
visitTerminator(II); |
3856 |
visitTerminator(II); |
| 3857 |
} |
3857 |
} |
| 3858 |
|
3858 |
|
| 3859 |
/// visitUnaryOperator - Check the argument to the unary operator. |
3859 |
/// visitUnaryOperator - Check the argument to the unary operator. |
| 3860 |
/// |
3860 |
/// |
| 3861 |
void Verifier::visitUnaryOperator(UnaryOperator &U) { |
3861 |
void Verifier::visitUnaryOperator(UnaryOperator &U) { |
| 3862 |
Check(U.getType() == U.getOperand(0)->getType(), |
3862 |
Check(U.getType() == U.getOperand(0)->getType(), |
| 3863 |
"Unary operators must have same type for" |
3863 |
"Unary operators must have same type for" |
| 3864 |
"operands and result!", |
3864 |
"operands and result!", |
| 3865 |
&U); |
3865 |
&U); |
| 3866 |
|
3866 |
|
| 3867 |
switch (U.getOpcode()) { |
3867 |
switch (U.getOpcode()) { |
| 3868 |
// Check that floating-point arithmetic operators are only used with |
3868 |
// Check that floating-point arithmetic operators are only used with |
| 3869 |
// floating-point operands. |
3869 |
// floating-point operands. |
| 3870 |
case Instruction::FNeg: |
3870 |
case Instruction::FNeg: |
| 3871 |
Check(U.getType()->isFPOrFPVectorTy(), |
3871 |
Check(U.getType()->isFPOrFPVectorTy(), |
| 3872 |
"FNeg operator only works with float types!", &U); |
3872 |
"FNeg operator only works with float types!", &U); |
| 3873 |
break; |
3873 |
break; |
| 3874 |
default: |
3874 |
default: |
| 3875 |
llvm_unreachable("Unknown UnaryOperator opcode!"); |
3875 |
llvm_unreachable("Unknown UnaryOperator opcode!"); |
| 3876 |
} |
3876 |
} |
| 3877 |
|
3877 |
|
| 3878 |
visitInstruction(U); |
3878 |
visitInstruction(U); |
| 3879 |
} |
3879 |
} |
| 3880 |
|
3880 |
|
| 3881 |
/// visitBinaryOperator - Check that both arguments to the binary operator are |
3881 |
/// visitBinaryOperator - Check that both arguments to the binary operator are |
| 3882 |
/// of the same type! |
3882 |
/// of the same type! |
| 3883 |
/// |
3883 |
/// |
| 3884 |
void Verifier::visitBinaryOperator(BinaryOperator &B) { |
3884 |
void Verifier::visitBinaryOperator(BinaryOperator &B) { |
| 3885 |
Check(B.getOperand(0)->getType() == B.getOperand(1)->getType(), |
3885 |
Check(B.getOperand(0)->getType() == B.getOperand(1)->getType(), |
| 3886 |
"Both operands to a binary operator are not of the same type!", &B); |
3886 |
"Both operands to a binary operator are not of the same type!", &B); |
| 3887 |
|
3887 |
|
| 3888 |
switch (B.getOpcode()) { |
3888 |
switch (B.getOpcode()) { |
| 3889 |
// Check that integer arithmetic operators are only used with |
3889 |
// Check that integer arithmetic operators are only used with |
| 3890 |
// integral operands. |
3890 |
// integral operands. |
| 3891 |
case Instruction::Add: |
3891 |
case Instruction::Add: |
| 3892 |
case Instruction::Sub: |
3892 |
case Instruction::Sub: |
| 3893 |
case Instruction::Mul: |
3893 |
case Instruction::Mul: |
| 3894 |
case Instruction::SDiv: |
3894 |
case Instruction::SDiv: |
| 3895 |
case Instruction::UDiv: |
3895 |
case Instruction::UDiv: |
| 3896 |
case Instruction::SRem: |
3896 |
case Instruction::SRem: |
| 3897 |
case Instruction::URem: |
3897 |
case Instruction::URem: |
| 3898 |
Check(B.getType()->isIntOrIntVectorTy(), |
3898 |
Check(B.getType()->isIntOrIntVectorTy(), |
| 3899 |
"Integer arithmetic operators only work with integral types!", &B); |
3899 |
"Integer arithmetic operators only work with integral types!", &B); |
| 3900 |
Check(B.getType() == B.getOperand(0)->getType(), |
3900 |
Check(B.getType() == B.getOperand(0)->getType(), |
| 3901 |
"Integer arithmetic operators must have same type " |
3901 |
"Integer arithmetic operators must have same type " |
| 3902 |
"for operands and result!", |
3902 |
"for operands and result!", |
| 3903 |
&B); |
3903 |
&B); |
| 3904 |
break; |
3904 |
break; |
| 3905 |
// Check that floating-point arithmetic operators are only used with |
3905 |
// Check that floating-point arithmetic operators are only used with |
| 3906 |
// floating-point operands. |
3906 |
// floating-point operands. |
| 3907 |
case Instruction::FAdd: |
3907 |
case Instruction::FAdd: |
| 3908 |
case Instruction::FSub: |
3908 |
case Instruction::FSub: |
| 3909 |
case Instruction::FMul: |
3909 |
case Instruction::FMul: |
| 3910 |
case Instruction::FDiv: |
3910 |
case Instruction::FDiv: |
| 3911 |
case Instruction::FRem: |
3911 |
case Instruction::FRem: |
| 3912 |
Check(B.getType()->isFPOrFPVectorTy(), |
3912 |
Check(B.getType()->isFPOrFPVectorTy(), |
| 3913 |
"Floating-point arithmetic operators only work with " |
3913 |
"Floating-point arithmetic operators only work with " |
| 3914 |
"floating-point types!", |
3914 |
"floating-point types!", |
| 3915 |
&B); |
3915 |
&B); |
| 3916 |
Check(B.getType() == B.getOperand(0)->getType(), |
3916 |
Check(B.getType() == B.getOperand(0)->getType(), |
| 3917 |
"Floating-point arithmetic operators must have same type " |
3917 |
"Floating-point arithmetic operators must have same type " |
| 3918 |
"for operands and result!", |
3918 |
"for operands and result!", |
| 3919 |
&B); |
3919 |
&B); |
| 3920 |
break; |
3920 |
break; |
| 3921 |
// Check that logical operators are only used with integral operands. |
3921 |
// Check that logical operators are only used with integral operands. |
| 3922 |
case Instruction::And: |
3922 |
case Instruction::And: |
| 3923 |
case Instruction::Or: |
3923 |
case Instruction::Or: |
| 3924 |
case Instruction::Xor: |
3924 |
case Instruction::Xor: |
| 3925 |
Check(B.getType()->isIntOrIntVectorTy(), |
3925 |
Check(B.getType()->isIntOrIntVectorTy(), |
| 3926 |
"Logical operators only work with integral types!", &B); |
3926 |
"Logical operators only work with integral types!", &B); |
| 3927 |
Check(B.getType() == B.getOperand(0)->getType(), |
3927 |
Check(B.getType() == B.getOperand(0)->getType(), |
| 3928 |
"Logical operators must have same type for operands and result!", &B); |
3928 |
"Logical operators must have same type for operands and result!", &B); |
| 3929 |
break; |
3929 |
break; |
| 3930 |
case Instruction::Shl: |
3930 |
case Instruction::Shl: |
| 3931 |
case Instruction::LShr: |
3931 |
case Instruction::LShr: |
| 3932 |
case Instruction::AShr: |
3932 |
case Instruction::AShr: |
| 3933 |
Check(B.getType()->isIntOrIntVectorTy(), |
3933 |
Check(B.getType()->isIntOrIntVectorTy(), |
| 3934 |
"Shifts only work with integral types!", &B); |
3934 |
"Shifts only work with integral types!", &B); |
| 3935 |
Check(B.getType() == B.getOperand(0)->getType(), |
3935 |
Check(B.getType() == B.getOperand(0)->getType(), |
| 3936 |
"Shift return type must be same as operands!", &B); |
3936 |
"Shift return type must be same as operands!", &B); |
| 3937 |
break; |
3937 |
break; |
| 3938 |
default: |
3938 |
default: |
| 3939 |
llvm_unreachable("Unknown BinaryOperator opcode!"); |
3939 |
llvm_unreachable("Unknown BinaryOperator opcode!"); |
| 3940 |
} |
3940 |
} |
| 3941 |
|
3941 |
|
| 3942 |
visitInstruction(B); |
3942 |
visitInstruction(B); |
| 3943 |
} |
3943 |
} |
| 3944 |
|
3944 |
|
| 3945 |
void Verifier::visitICmpInst(ICmpInst &IC) { |
3945 |
void Verifier::visitICmpInst(ICmpInst &IC) { |
| 3946 |
// Check that the operands are the same type |
3946 |
// Check that the operands are the same type |
| 3947 |
Type *Op0Ty = IC.getOperand(0)->getType(); |
3947 |
Type *Op0Ty = IC.getOperand(0)->getType(); |
| 3948 |
Type *Op1Ty = IC.getOperand(1)->getType(); |
3948 |
Type *Op1Ty = IC.getOperand(1)->getType(); |
| 3949 |
Check(Op0Ty == Op1Ty, |
3949 |
Check(Op0Ty == Op1Ty, |
| 3950 |
"Both operands to ICmp instruction are not of the same type!", &IC); |
3950 |
"Both operands to ICmp instruction are not of the same type!", &IC); |
| 3951 |
// Check that the operands are the right type |
3951 |
// Check that the operands are the right type |
| 3952 |
Check(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy(), |
3952 |
Check(Op0Ty->isIntOrIntVectorTy() || Op0Ty->isPtrOrPtrVectorTy(), |
| 3953 |
"Invalid operand types for ICmp instruction", &IC); |
3953 |
"Invalid operand types for ICmp instruction", &IC); |
| 3954 |
// Check that the predicate is valid. |
3954 |
// Check that the predicate is valid. |
| 3955 |
Check(IC.isIntPredicate(), "Invalid predicate in ICmp instruction!", &IC); |
3955 |
Check(IC.isIntPredicate(), "Invalid predicate in ICmp instruction!", &IC); |
| 3956 |
|
3956 |
|
| 3957 |
visitInstruction(IC); |
3957 |
visitInstruction(IC); |
| 3958 |
} |
3958 |
} |
| 3959 |
|
3959 |
|
| 3960 |
void Verifier::visitFCmpInst(FCmpInst &FC) { |
3960 |
void Verifier::visitFCmpInst(FCmpInst &FC) { |
| 3961 |
// Check that the operands are the same type |
3961 |
// Check that the operands are the same type |
| 3962 |
Type *Op0Ty = FC.getOperand(0)->getType(); |
3962 |
Type *Op0Ty = FC.getOperand(0)->getType(); |
| 3963 |
Type *Op1Ty = FC.getOperand(1)->getType(); |
3963 |
Type *Op1Ty = FC.getOperand(1)->getType(); |
| 3964 |
Check(Op0Ty == Op1Ty, |
3964 |
Check(Op0Ty == Op1Ty, |
| 3965 |
"Both operands to FCmp instruction are not of the same type!", &FC); |
3965 |
"Both operands to FCmp instruction are not of the same type!", &FC); |
| 3966 |
// Check that the operands are the right type |
3966 |
// Check that the operands are the right type |
| 3967 |
Check(Op0Ty->isFPOrFPVectorTy(), "Invalid operand types for FCmp instruction", |
3967 |
Check(Op0Ty->isFPOrFPVectorTy(), "Invalid operand types for FCmp instruction", |
| 3968 |
&FC); |
3968 |
&FC); |
| 3969 |
// Check that the predicate is valid. |
3969 |
// Check that the predicate is valid. |
| 3970 |
Check(FC.isFPPredicate(), "Invalid predicate in FCmp instruction!", &FC); |
3970 |
Check(FC.isFPPredicate(), "Invalid predicate in FCmp instruction!", &FC); |
| 3971 |
|
3971 |
|
| 3972 |
visitInstruction(FC); |
3972 |
visitInstruction(FC); |
| 3973 |
} |
3973 |
} |
| 3974 |
|
3974 |
|
| 3975 |
void Verifier::visitExtractElementInst(ExtractElementInst &EI) { |
3975 |
void Verifier::visitExtractElementInst(ExtractElementInst &EI) { |
| 3976 |
Check(ExtractElementInst::isValidOperands(EI.getOperand(0), EI.getOperand(1)), |
3976 |
Check(ExtractElementInst::isValidOperands(EI.getOperand(0), EI.getOperand(1)), |
| 3977 |
"Invalid extractelement operands!", &EI); |
3977 |
"Invalid extractelement operands!", &EI); |
| 3978 |
visitInstruction(EI); |
3978 |
visitInstruction(EI); |
| 3979 |
} |
3979 |
} |
| 3980 |
|
3980 |
|
| 3981 |
void Verifier::visitInsertElementInst(InsertElementInst &IE) { |
3981 |
void Verifier::visitInsertElementInst(InsertElementInst &IE) { |
| 3982 |
Check(InsertElementInst::isValidOperands(IE.getOperand(0), IE.getOperand(1), |
3982 |
Check(InsertElementInst::isValidOperands(IE.getOperand(0), IE.getOperand(1), |
| 3983 |
IE.getOperand(2)), |
3983 |
IE.getOperand(2)), |
| 3984 |
"Invalid insertelement operands!", &IE); |
3984 |
"Invalid insertelement operands!", &IE); |
| 3985 |
visitInstruction(IE); |
3985 |
visitInstruction(IE); |
| 3986 |
} |
3986 |
} |
| 3987 |
|
3987 |
|
| 3988 |
void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) { |
3988 |
void Verifier::visitShuffleVectorInst(ShuffleVectorInst &SV) { |
| 3989 |
Check(ShuffleVectorInst::isValidOperands(SV.getOperand(0), SV.getOperand(1), |
3989 |
Check(ShuffleVectorInst::isValidOperands(SV.getOperand(0), SV.getOperand(1), |
| 3990 |
SV.getShuffleMask()), |
3990 |
SV.getShuffleMask()), |
| 3991 |
"Invalid shufflevector operands!", &SV); |
3991 |
"Invalid shufflevector operands!", &SV); |
| 3992 |
visitInstruction(SV); |
3992 |
visitInstruction(SV); |
| 3993 |
} |
3993 |
} |
| 3994 |
|
3994 |
|
| 3995 |
void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) { |
3995 |
void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) { |
| 3996 |
Type *TargetTy = GEP.getPointerOperandType()->getScalarType(); |
3996 |
Type *TargetTy = GEP.getPointerOperandType()->getScalarType(); |
| 3997 |
|
3997 |
|
| 3998 |
Check(isa(TargetTy), |
3998 |
Check(isa(TargetTy), |
| 3999 |
"GEP base pointer is not a vector or a vector of pointers", &GEP); |
3999 |
"GEP base pointer is not a vector or a vector of pointers", &GEP); |
| 4000 |
Check(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP); |
4000 |
Check(GEP.getSourceElementType()->isSized(), "GEP into unsized type!", &GEP); |
| 4001 |
|
4001 |
|
| 4002 |
if (auto *STy = dyn_cast(GEP.getSourceElementType())) { |
4002 |
if (auto *STy = dyn_cast(GEP.getSourceElementType())) { |
| 4003 |
SmallPtrSet Visited; |
4003 |
SmallPtrSet Visited; |
| 4004 |
Check(!STy->containsScalableVectorType(&Visited), |
4004 |
Check(!STy->containsScalableVectorType(&Visited), |
| 4005 |
"getelementptr cannot target structure that contains scalable vector" |
4005 |
"getelementptr cannot target structure that contains scalable vector" |
| 4006 |
"type", |
4006 |
"type", |
| 4007 |
&GEP); |
4007 |
&GEP); |
| 4008 |
} |
4008 |
} |
| 4009 |
|
4009 |
|
| 4010 |
SmallVector Idxs(GEP.indices()); |
4010 |
SmallVector Idxs(GEP.indices()); |
| 4011 |
Check( |
4011 |
Check( |
| 4012 |
all_of(Idxs, [](Value *V) { return V->getType()->isIntOrIntVectorTy(); }), |
4012 |
all_of(Idxs, [](Value *V) { return V->getType()->isIntOrIntVectorTy(); }), |
| 4013 |
"GEP indexes must be integers", &GEP); |
4013 |
"GEP indexes must be integers", &GEP); |
| 4014 |
Type *ElTy = |
4014 |
Type *ElTy = |
| 4015 |
GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs); |
4015 |
GetElementPtrInst::getIndexedType(GEP.getSourceElementType(), Idxs); |
| 4016 |
Check(ElTy, "Invalid indices for GEP pointer type!", &GEP); |
4016 |
Check(ElTy, "Invalid indices for GEP pointer type!", &GEP); |
| 4017 |
|
4017 |
|
| 4018 |
Check(GEP.getType()->isPtrOrPtrVectorTy() && |
4018 |
Check(GEP.getType()->isPtrOrPtrVectorTy() && |
| 4019 |
GEP.getResultElementType() == ElTy, |
4019 |
GEP.getResultElementType() == ElTy, |
| 4020 |
"GEP is not of right type for indices!", &GEP, ElTy); |
4020 |
"GEP is not of right type for indices!", &GEP, ElTy); |
| 4021 |
|
4021 |
|
| 4022 |
if (auto *GEPVTy = dyn_cast(GEP.getType())) { |
4022 |
if (auto *GEPVTy = dyn_cast(GEP.getType())) { |
| 4023 |
// Additional checks for vector GEPs. |
4023 |
// Additional checks for vector GEPs. |
| 4024 |
ElementCount GEPWidth = GEPVTy->getElementCount(); |
4024 |
ElementCount GEPWidth = GEPVTy->getElementCount(); |
| 4025 |
if (GEP.getPointerOperandType()->isVectorTy()) |
4025 |
if (GEP.getPointerOperandType()->isVectorTy()) |
| 4026 |
Check( |
4026 |
Check( |
| 4027 |
GEPWidth == |
4027 |
GEPWidth == |
| 4028 |
cast(GEP.getPointerOperandType())->getElementCount(), |
4028 |
cast(GEP.getPointerOperandType())->getElementCount(), |
| 4029 |
"Vector GEP result width doesn't match operand's", &GEP); |
4029 |
"Vector GEP result width doesn't match operand's", &GEP); |
| 4030 |
for (Value *Idx : Idxs) { |
4030 |
for (Value *Idx : Idxs) { |
| 4031 |
Type *IndexTy = Idx->getType(); |
4031 |
Type *IndexTy = Idx->getType(); |
| 4032 |
if (auto *IndexVTy = dyn_cast(IndexTy)) { |
4032 |
if (auto *IndexVTy = dyn_cast(IndexTy)) { |
| 4033 |
ElementCount IndexWidth = IndexVTy->getElementCount(); |
4033 |
ElementCount IndexWidth = IndexVTy->getElementCount(); |
| 4034 |
Check(IndexWidth == GEPWidth, "Invalid GEP index vector width", &GEP); |
4034 |
Check(IndexWidth == GEPWidth, "Invalid GEP index vector width", &GEP); |
| 4035 |
} |
4035 |
} |
| 4036 |
Check(IndexTy->isIntOrIntVectorTy(), |
4036 |
Check(IndexTy->isIntOrIntVectorTy(), |
| 4037 |
"All GEP indices should be of integer type"); |
4037 |
"All GEP indices should be of integer type"); |
| 4038 |
} |
4038 |
} |
| 4039 |
} |
4039 |
} |
| 4040 |
|
4040 |
|
| 4041 |
if (auto *PTy = dyn_cast(GEP.getType())) { |
4041 |
if (auto *PTy = dyn_cast(GEP.getType())) { |
| 4042 |
Check(GEP.getAddressSpace() == PTy->getAddressSpace(), |
4042 |
Check(GEP.getAddressSpace() == PTy->getAddressSpace(), |
| 4043 |
"GEP address space doesn't match type", &GEP); |
4043 |
"GEP address space doesn't match type", &GEP); |
| 4044 |
} |
4044 |
} |
| 4045 |
|
4045 |
|
| 4046 |
visitInstruction(GEP); |
4046 |
visitInstruction(GEP); |
| 4047 |
} |
4047 |
} |
| 4048 |
|
4048 |
|
| 4049 |
static bool isContiguous(const ConstantRange &A, const ConstantRange &B) { |
4049 |
static bool isContiguous(const ConstantRange &A, const ConstantRange &B) { |
| 4050 |
return A.getUpper() == B.getLower() || A.getLower() == B.getUpper(); |
4050 |
return A.getUpper() == B.getLower() || A.getLower() == B.getUpper(); |
| 4051 |
} |
4051 |
} |
| 4052 |
|
4052 |
|
| 4053 |
/// Verify !range and !absolute_symbol metadata. These have the same |
4053 |
/// Verify !range and !absolute_symbol metadata. These have the same |
| 4054 |
/// restrictions, except !absolute_symbol allows the full set. |
4054 |
/// restrictions, except !absolute_symbol allows the full set. |
| 4055 |
void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range, |
4055 |
void Verifier::verifyRangeMetadata(const Value &I, const MDNode *Range, |
| 4056 |
Type *Ty, bool IsAbsoluteSymbol) { |
4056 |
Type *Ty, bool IsAbsoluteSymbol) { |
| 4057 |
unsigned NumOperands = Range->getNumOperands(); |
4057 |
unsigned NumOperands = Range->getNumOperands(); |
| 4058 |
Check(NumOperands % 2 == 0, "Unfinished range!", Range); |
4058 |
Check(NumOperands % 2 == 0, "Unfinished range!", Range); |
| 4059 |
unsigned NumRanges = NumOperands / 2; |
4059 |
unsigned NumRanges = NumOperands / 2; |
| 4060 |
Check(NumRanges >= 1, "It should have at least one range!", Range); |
4060 |
Check(NumRanges >= 1, "It should have at least one range!", Range); |
| 4061 |
|
4061 |
|
| 4062 |
ConstantRange LastRange(1, true); // Dummy initial value |
4062 |
ConstantRange LastRange(1, true); // Dummy initial value |
| 4063 |
for (unsigned i = 0; i < NumRanges; ++i) { |
4063 |
for (unsigned i = 0; i < NumRanges; ++i) { |
| 4064 |
ConstantInt *Low = |
4064 |
ConstantInt *Low = |
| 4065 |
mdconst::dyn_extract(Range->getOperand(2 * i)); |
4065 |
mdconst::dyn_extract(Range->getOperand(2 * i)); |
| 4066 |
Check(Low, "The lower limit must be an integer!", Low); |
4066 |
Check(Low, "The lower limit must be an integer!", Low); |
| 4067 |
ConstantInt *High = |
4067 |
ConstantInt *High = |
| 4068 |
mdconst::dyn_extract(Range->getOperand(2 * i + 1)); |
4068 |
mdconst::dyn_extract(Range->getOperand(2 * i + 1)); |
| 4069 |
Check(High, "The upper limit must be an integer!", High); |
4069 |
Check(High, "The upper limit must be an integer!", High); |
| 4070 |
Check(High->getType() == Low->getType() && |
4070 |
Check(High->getType() == Low->getType() && |
| 4071 |
High->getType() == Ty->getScalarType(), |
4071 |
High->getType() == Ty->getScalarType(), |
| 4072 |
"Range types must match instruction type!", &I); |
4072 |
"Range types must match instruction type!", &I); |
| 4073 |
|
4073 |
|
| 4074 |
APInt HighV = High->getValue(); |
4074 |
APInt HighV = High->getValue(); |
| 4075 |
APInt LowV = Low->getValue(); |
4075 |
APInt LowV = Low->getValue(); |
| 4076 |
|
4076 |
|
| 4077 |
// ConstantRange asserts if the ranges are the same except for the min/max |
4077 |
// ConstantRange asserts if the ranges are the same except for the min/max |
| 4078 |
// value. Leave the cases it tolerates for the empty range error below. |
4078 |
// value. Leave the cases it tolerates for the empty range error below. |
| 4079 |
Check(LowV != HighV || LowV.isMaxValue() || LowV.isMinValue(), |
4079 |
Check(LowV != HighV || LowV.isMaxValue() || LowV.isMinValue(), |
| 4080 |
"The upper and lower limits cannot be the same value", &I); |
4080 |
"The upper and lower limits cannot be the same value", &I); |
| 4081 |
|
4081 |
|
| 4082 |
ConstantRange CurRange(LowV, HighV); |
4082 |
ConstantRange CurRange(LowV, HighV); |
| 4083 |
Check(!CurRange.isEmptySet() && (IsAbsoluteSymbol || !CurRange.isFullSet()), |
4083 |
Check(!CurRange.isEmptySet() && (IsAbsoluteSymbol || !CurRange.isFullSet()), |
| 4084 |
"Range must not be empty!", Range); |
4084 |
"Range must not be empty!", Range); |
| 4085 |
if (i != 0) { |
4085 |
if (i != 0) { |
| 4086 |
Check(CurRange.intersectWith(LastRange).isEmptySet(), |
4086 |
Check(CurRange.intersectWith(LastRange).isEmptySet(), |
| 4087 |
"Intervals are overlapping", Range); |
4087 |
"Intervals are overlapping", Range); |
| 4088 |
Check(LowV.sgt(LastRange.getLower()), "Intervals are not in order", |
4088 |
Check(LowV.sgt(LastRange.getLower()), "Intervals are not in order", |
| 4089 |
Range); |
4089 |
Range); |
| 4090 |
Check(!isContiguous(CurRange, LastRange), "Intervals are contiguous", |
4090 |
Check(!isContiguous(CurRange, LastRange), "Intervals are contiguous", |
| 4091 |
Range); |
4091 |
Range); |
| 4092 |
} |
4092 |
} |
| 4093 |
LastRange = ConstantRange(LowV, HighV); |
4093 |
LastRange = ConstantRange(LowV, HighV); |
| 4094 |
} |
4094 |
} |
| 4095 |
if (NumRanges > 2) { |
4095 |
if (NumRanges > 2) { |
| 4096 |
APInt FirstLow = |
4096 |
APInt FirstLow = |
| 4097 |
mdconst::dyn_extract(Range->getOperand(0))->getValue(); |
4097 |
mdconst::dyn_extract(Range->getOperand(0))->getValue(); |
| 4098 |
APInt FirstHigh = |
4098 |
APInt FirstHigh = |
| 4099 |
mdconst::dyn_extract(Range->getOperand(1))->getValue(); |
4099 |
mdconst::dyn_extract(Range->getOperand(1))->getValue(); |
| 4100 |
ConstantRange FirstRange(FirstLow, FirstHigh); |
4100 |
ConstantRange FirstRange(FirstLow, FirstHigh); |
| 4101 |
Check(FirstRange.intersectWith(LastRange).isEmptySet(), |
4101 |
Check(FirstRange.intersectWith(LastRange).isEmptySet(), |
| 4102 |
"Intervals are overlapping", Range); |
4102 |
"Intervals are overlapping", Range); |
| 4103 |
Check(!isContiguous(FirstRange, LastRange), "Intervals are contiguous", |
4103 |
Check(!isContiguous(FirstRange, LastRange), "Intervals are contiguous", |
| 4104 |
Range); |
4104 |
Range); |
| 4105 |
} |
4105 |
} |
| 4106 |
} |
4106 |
} |
| 4107 |
|
4107 |
|
| 4108 |
void Verifier::visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty) { |
4108 |
void Verifier::visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty) { |
| 4109 |
assert(Range && Range == I.getMetadata(LLVMContext::MD_range) && |
4109 |
assert(Range && Range == I.getMetadata(LLVMContext::MD_range) && |
| 4110 |
"precondition violation"); |
4110 |
"precondition violation"); |
| 4111 |
verifyRangeMetadata(I, Range, Ty, false); |
4111 |
verifyRangeMetadata(I, Range, Ty, false); |
| 4112 |
} |
4112 |
} |
| 4113 |
|
4113 |
|
| 4114 |
void Verifier::checkAtomicMemAccessSize(Type *Ty, const Instruction *I) { |
4114 |
void Verifier::checkAtomicMemAccessSize(Type *Ty, const Instruction *I) { |
| 4115 |
unsigned Size = DL.getTypeSizeInBits(Ty); |
4115 |
unsigned Size = DL.getTypeSizeInBits(Ty); |
| 4116 |
Check(Size >= 8, "atomic memory access' size must be byte-sized", Ty, I); |
4116 |
Check(Size >= 8, "atomic memory access' size must be byte-sized", Ty, I); |
| 4117 |
Check(!(Size & (Size - 1)), |
4117 |
Check(!(Size & (Size - 1)), |
| 4118 |
"atomic memory access' operand must have a power-of-two size", Ty, I); |
4118 |
"atomic memory access' operand must have a power-of-two size", Ty, I); |
| 4119 |
} |
4119 |
} |
| 4120 |
|
4120 |
|
| 4121 |
void Verifier::visitLoadInst(LoadInst &LI) { |
4121 |
void Verifier::visitLoadInst(LoadInst &LI) { |
| 4122 |
PointerType *PTy = dyn_cast(LI.getOperand(0)->getType()); |
4122 |
PointerType *PTy = dyn_cast(LI.getOperand(0)->getType()); |
| 4123 |
Check(PTy, "Load operand must be a pointer.", &LI); |
4123 |
Check(PTy, "Load operand must be a pointer.", &LI); |
| 4124 |
Type *ElTy = LI.getType(); |
4124 |
Type *ElTy = LI.getType(); |
| 4125 |
if (MaybeAlign A = LI.getAlign()) { |
4125 |
if (MaybeAlign A = LI.getAlign()) { |
| 4126 |
Check(A->value() <= Value::MaximumAlignment, |
4126 |
Check(A->value() <= Value::MaximumAlignment, |
| 4127 |
"huge alignment values are unsupported", &LI); |
4127 |
"huge alignment values are unsupported", &LI); |
| 4128 |
} |
4128 |
} |
| 4129 |
Check(ElTy->isSized(), "loading unsized types is not allowed", &LI); |
4129 |
Check(ElTy->isSized(), "loading unsized types is not allowed", &LI); |
| 4130 |
if (LI.isAtomic()) { |
4130 |
if (LI.isAtomic()) { |
| 4131 |
Check(LI.getOrdering() != AtomicOrdering::Release && |
4131 |
Check(LI.getOrdering() != AtomicOrdering::Release && |
| 4132 |
LI.getOrdering() != AtomicOrdering::AcquireRelease, |
4132 |
LI.getOrdering() != AtomicOrdering::AcquireRelease, |
| 4133 |
"Load cannot have Release ordering", &LI); |
4133 |
"Load cannot have Release ordering", &LI); |
| 4134 |
Check(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(), |
4134 |
Check(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(), |
| 4135 |
"atomic load operand must have integer, pointer, or floating point " |
4135 |
"atomic load operand must have integer, pointer, or floating point " |
| 4136 |
"type!", |
4136 |
"type!", |
| 4137 |
ElTy, &LI); |
4137 |
ElTy, &LI); |
| 4138 |
checkAtomicMemAccessSize(ElTy, &LI); |
4138 |
checkAtomicMemAccessSize(ElTy, &LI); |
| 4139 |
} else { |
4139 |
} else { |
| 4140 |
Check(LI.getSyncScopeID() == SyncScope::System, |
4140 |
Check(LI.getSyncScopeID() == SyncScope::System, |
| 4141 |
"Non-atomic load cannot have SynchronizationScope specified", &LI); |
4141 |
"Non-atomic load cannot have SynchronizationScope specified", &LI); |
| 4142 |
} |
4142 |
} |
| 4143 |
|
4143 |
|
| 4144 |
visitInstruction(LI); |
4144 |
visitInstruction(LI); |
| 4145 |
} |
4145 |
} |
| 4146 |
|
4146 |
|
| 4147 |
void Verifier::visitStoreInst(StoreInst &SI) { |
4147 |
void Verifier::visitStoreInst(StoreInst &SI) { |
| 4148 |
PointerType *PTy = dyn_cast(SI.getOperand(1)->getType()); |
4148 |
PointerType *PTy = dyn_cast(SI.getOperand(1)->getType()); |
| 4149 |
Check(PTy, "Store operand must be a pointer.", &SI); |
4149 |
Check(PTy, "Store operand must be a pointer.", &SI); |
| 4150 |
Type *ElTy = SI.getOperand(0)->getType(); |
4150 |
Type *ElTy = SI.getOperand(0)->getType(); |
| 4151 |
if (MaybeAlign A = SI.getAlign()) { |
4151 |
if (MaybeAlign A = SI.getAlign()) { |
| 4152 |
Check(A->value() <= Value::MaximumAlignment, |
4152 |
Check(A->value() <= Value::MaximumAlignment, |
| 4153 |
"huge alignment values are unsupported", &SI); |
4153 |
"huge alignment values are unsupported", &SI); |
| 4154 |
} |
4154 |
} |
| 4155 |
Check(ElTy->isSized(), "storing unsized types is not allowed", &SI); |
4155 |
Check(ElTy->isSized(), "storing unsized types is not allowed", &SI); |
| 4156 |
if (SI.isAtomic()) { |
4156 |
if (SI.isAtomic()) { |
| 4157 |
Check(SI.getOrdering() != AtomicOrdering::Acquire && |
4157 |
Check(SI.getOrdering() != AtomicOrdering::Acquire && |
| 4158 |
SI.getOrdering() != AtomicOrdering::AcquireRelease, |
4158 |
SI.getOrdering() != AtomicOrdering::AcquireRelease, |
| 4159 |
"Store cannot have Acquire ordering", &SI); |
4159 |
"Store cannot have Acquire ordering", &SI); |
| 4160 |
Check(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(), |
4160 |
Check(ElTy->isIntOrPtrTy() || ElTy->isFloatingPointTy(), |
| 4161 |
"atomic store operand must have integer, pointer, or floating point " |
4161 |
"atomic store operand must have integer, pointer, or floating point " |
| 4162 |
"type!", |
4162 |
"type!", |
| 4163 |
ElTy, &SI); |
4163 |
ElTy, &SI); |
| 4164 |
checkAtomicMemAccessSize(ElTy, &SI); |
4164 |
checkAtomicMemAccessSize(ElTy, &SI); |
| 4165 |
} else { |
4165 |
} else { |
| 4166 |
Check(SI.getSyncScopeID() == SyncScope::System, |
4166 |
Check(SI.getSyncScopeID() == SyncScope::System, |
| 4167 |
"Non-atomic store cannot have SynchronizationScope specified", &SI); |
4167 |
"Non-atomic store cannot have SynchronizationScope specified", &SI); |
| 4168 |
} |
4168 |
} |
| 4169 |
visitInstruction(SI); |
4169 |
visitInstruction(SI); |
| 4170 |
} |
4170 |
} |
| 4171 |
|
4171 |
|
| 4172 |
/// Check that SwiftErrorVal is used as a swifterror argument in CS. |
4172 |
/// Check that SwiftErrorVal is used as a swifterror argument in CS. |
| 4173 |
void Verifier::verifySwiftErrorCall(CallBase &Call, |
4173 |
void Verifier::verifySwiftErrorCall(CallBase &Call, |
| 4174 |
const Value *SwiftErrorVal) { |
4174 |
const Value *SwiftErrorVal) { |
| 4175 |
for (const auto &I : llvm::enumerate(Call.args())) { |
4175 |
for (const auto &I : llvm::enumerate(Call.args())) { |
| 4176 |
if (I.value() == SwiftErrorVal) { |
4176 |
if (I.value() == SwiftErrorVal) { |
| 4177 |
Check(Call.paramHasAttr(I.index(), Attribute::SwiftError), |
4177 |
Check(Call.paramHasAttr(I.index(), Attribute::SwiftError), |
| 4178 |
"swifterror value when used in a callsite should be marked " |
4178 |
"swifterror value when used in a callsite should be marked " |
| 4179 |
"with swifterror attribute", |
4179 |
"with swifterror attribute", |
| 4180 |
SwiftErrorVal, Call); |
4180 |
SwiftErrorVal, Call); |
| 4181 |
} |
4181 |
} |
| 4182 |
} |
4182 |
} |
| 4183 |
} |
4183 |
} |
| 4184 |
|
4184 |
|
| 4185 |
void Verifier::verifySwiftErrorValue(const Value *SwiftErrorVal) { |
4185 |
void Verifier::verifySwiftErrorValue(const Value *SwiftErrorVal) { |
| 4186 |
// Check that swifterror value is only used by loads, stores, or as |
4186 |
// Check that swifterror value is only used by loads, stores, or as |
| 4187 |
// a swifterror argument. |
4187 |
// a swifterror argument. |
| 4188 |
for (const User *U : SwiftErrorVal->users()) { |
4188 |
for (const User *U : SwiftErrorVal->users()) { |
| 4189 |
Check(isa(U) || isa(U) || isa(U) || |
4189 |
Check(isa(U) || isa(U) || isa(U) || |
| 4190 |
isa(U), |
4190 |
isa(U), |
| 4191 |
"swifterror value can only be loaded and stored from, or " |
4191 |
"swifterror value can only be loaded and stored from, or " |
| 4192 |
"as a swifterror argument!", |
4192 |
"as a swifterror argument!", |
| 4193 |
SwiftErrorVal, U); |
4193 |
SwiftErrorVal, U); |
| 4194 |
// If it is used by a store, check it is the second operand. |
4194 |
// If it is used by a store, check it is the second operand. |
| 4195 |
if (auto StoreI = dyn_cast(U)) |
4195 |
if (auto StoreI = dyn_cast(U)) |
| 4196 |
Check(StoreI->getOperand(1) == SwiftErrorVal, |
4196 |
Check(StoreI->getOperand(1) == SwiftErrorVal, |
| 4197 |
"swifterror value should be the second operand when used " |
4197 |
"swifterror value should be the second operand when used " |
| 4198 |
"by stores", |
4198 |
"by stores", |
| 4199 |
SwiftErrorVal, U); |
4199 |
SwiftErrorVal, U); |
| 4200 |
if (auto *Call = dyn_cast(U)) |
4200 |
if (auto *Call = dyn_cast(U)) |
| 4201 |
verifySwiftErrorCall(*const_cast(Call), SwiftErrorVal); |
4201 |
verifySwiftErrorCall(*const_cast(Call), SwiftErrorVal); |
| 4202 |
} |
4202 |
} |
| 4203 |
} |
4203 |
} |
| 4204 |
|
4204 |
|
| 4205 |
void Verifier::visitAllocaInst(AllocaInst &AI) { |
4205 |
void Verifier::visitAllocaInst(AllocaInst &AI) { |
| 4206 |
SmallPtrSet Visited; |
4206 |
SmallPtrSet Visited; |
| 4207 |
Check(AI.getAllocatedType()->isSized(&Visited), |
4207 |
Check(AI.getAllocatedType()->isSized(&Visited), |
| 4208 |
"Cannot allocate unsized type", &AI); |
4208 |
"Cannot allocate unsized type", &AI); |
| 4209 |
Check(AI.getArraySize()->getType()->isIntegerTy(), |
4209 |
Check(AI.getArraySize()->getType()->isIntegerTy(), |
| 4210 |
"Alloca array size must have integer type", &AI); |
4210 |
"Alloca array size must have integer type", &AI); |
| 4211 |
if (MaybeAlign A = AI.getAlign()) { |
4211 |
if (MaybeAlign A = AI.getAlign()) { |
| 4212 |
Check(A->value() <= Value::MaximumAlignment, |
4212 |
Check(A->value() <= Value::MaximumAlignment, |
| 4213 |
"huge alignment values are unsupported", &AI); |
4213 |
"huge alignment values are unsupported", &AI); |
| 4214 |
} |
4214 |
} |
| 4215 |
|
4215 |
|
| 4216 |
if (AI.isSwiftError()) { |
4216 |
if (AI.isSwiftError()) { |
| 4217 |
Check(AI.getAllocatedType()->isPointerTy(), |
4217 |
Check(AI.getAllocatedType()->isPointerTy(), |
| 4218 |
"swifterror alloca must have pointer type", &AI); |
4218 |
"swifterror alloca must have pointer type", &AI); |
| 4219 |
Check(!AI.isArrayAllocation(), |
4219 |
Check(!AI.isArrayAllocation(), |
| 4220 |
"swifterror alloca must not be array allocation", &AI); |
4220 |
"swifterror alloca must not be array allocation", &AI); |
| 4221 |
verifySwiftErrorValue(&AI); |
4221 |
verifySwiftErrorValue(&AI); |
| 4222 |
} |
4222 |
} |
| 4223 |
|
4223 |
|
| 4224 |
visitInstruction(AI); |
4224 |
visitInstruction(AI); |
| 4225 |
} |
4225 |
} |
| 4226 |
|
4226 |
|
| 4227 |
void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) { |
4227 |
void Verifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI) { |
| 4228 |
Type *ElTy = CXI.getOperand(1)->getType(); |
4228 |
Type *ElTy = CXI.getOperand(1)->getType(); |
| 4229 |
Check(ElTy->isIntOrPtrTy(), |
4229 |
Check(ElTy->isIntOrPtrTy(), |
| 4230 |
"cmpxchg operand must have integer or pointer type", ElTy, &CXI); |
4230 |
"cmpxchg operand must have integer or pointer type", ElTy, &CXI); |
| 4231 |
checkAtomicMemAccessSize(ElTy, &CXI); |
4231 |
checkAtomicMemAccessSize(ElTy, &CXI); |
| 4232 |
visitInstruction(CXI); |
4232 |
visitInstruction(CXI); |
| 4233 |
} |
4233 |
} |
| 4234 |
|
4234 |
|
| 4235 |
void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) { |
4235 |
void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) { |
| 4236 |
Check(RMWI.getOrdering() != AtomicOrdering::Unordered, |
4236 |
Check(RMWI.getOrdering() != AtomicOrdering::Unordered, |
| 4237 |
"atomicrmw instructions cannot be unordered.", &RMWI); |
4237 |
"atomicrmw instructions cannot be unordered.", &RMWI); |
| 4238 |
auto Op = RMWI.getOperation(); |
4238 |
auto Op = RMWI.getOperation(); |
| 4239 |
Type *ElTy = RMWI.getOperand(1)->getType(); |
4239 |
Type *ElTy = RMWI.getOperand(1)->getType(); |
| 4240 |
if (Op == AtomicRMWInst::Xchg) { |
4240 |
if (Op == AtomicRMWInst::Xchg) { |
| 4241 |
Check(ElTy->isIntegerTy() || ElTy->isFloatingPointTy() || |
4241 |
Check(ElTy->isIntegerTy() || ElTy->isFloatingPointTy() || |
| 4242 |
ElTy->isPointerTy(), |
4242 |
ElTy->isPointerTy(), |
| 4243 |
"atomicrmw " + AtomicRMWInst::getOperationName(Op) + |
4243 |
"atomicrmw " + AtomicRMWInst::getOperationName(Op) + |
| 4244 |
" operand must have integer or floating point type!", |
4244 |
" operand must have integer or floating point type!", |
| 4245 |
&RMWI, ElTy); |
4245 |
&RMWI, ElTy); |
| 4246 |
} else if (AtomicRMWInst::isFPOperation(Op)) { |
4246 |
} else if (AtomicRMWInst::isFPOperation(Op)) { |
| 4247 |
Check(ElTy->isFloatingPointTy(), |
4247 |
Check(ElTy->isFloatingPointTy(), |
| 4248 |
"atomicrmw " + AtomicRMWInst::getOperationName(Op) + |
4248 |
"atomicrmw " + AtomicRMWInst::getOperationName(Op) + |
| 4249 |
" operand must have floating point type!", |
4249 |
" operand must have floating point type!", |
| 4250 |
&RMWI, ElTy); |
4250 |
&RMWI, ElTy); |
| 4251 |
} else { |
4251 |
} else { |
| 4252 |
Check(ElTy->isIntegerTy(), |
4252 |
Check(ElTy->isIntegerTy(), |
| 4253 |
"atomicrmw " + AtomicRMWInst::getOperationName(Op) + |
4253 |
"atomicrmw " + AtomicRMWInst::getOperationName(Op) + |
| 4254 |
" operand must have integer type!", |
4254 |
" operand must have integer type!", |
| 4255 |
&RMWI, ElTy); |
4255 |
&RMWI, ElTy); |
| 4256 |
} |
4256 |
} |
| 4257 |
checkAtomicMemAccessSize(ElTy, &RMWI); |
4257 |
checkAtomicMemAccessSize(ElTy, &RMWI); |
| 4258 |
Check(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP, |
4258 |
Check(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP, |
| 4259 |
"Invalid binary operation!", &RMWI); |
4259 |
"Invalid binary operation!", &RMWI); |
| 4260 |
visitInstruction(RMWI); |
4260 |
visitInstruction(RMWI); |
| 4261 |
} |
4261 |
} |
| 4262 |
|
4262 |
|
| 4263 |
void Verifier::visitFenceInst(FenceInst &FI) { |
4263 |
void Verifier::visitFenceInst(FenceInst &FI) { |
| 4264 |
const AtomicOrdering Ordering = FI.getOrdering(); |
4264 |
const AtomicOrdering Ordering = FI.getOrdering(); |
| 4265 |
Check(Ordering == AtomicOrdering::Acquire || |
4265 |
Check(Ordering == AtomicOrdering::Acquire || |
| 4266 |
Ordering == AtomicOrdering::Release || |
4266 |
Ordering == AtomicOrdering::Release || |
| 4267 |
Ordering == AtomicOrdering::AcquireRelease || |
4267 |
Ordering == AtomicOrdering::AcquireRelease || |
| 4268 |
Ordering == AtomicOrdering::SequentiallyConsistent, |
4268 |
Ordering == AtomicOrdering::SequentiallyConsistent, |
| 4269 |
"fence instructions may only have acquire, release, acq_rel, or " |
4269 |
"fence instructions may only have acquire, release, acq_rel, or " |
| 4270 |
"seq_cst ordering.", |
4270 |
"seq_cst ordering.", |
| 4271 |
&FI); |
4271 |
&FI); |
| 4272 |
visitInstruction(FI); |
4272 |
visitInstruction(FI); |
| 4273 |
} |
4273 |
} |
| 4274 |
|
4274 |
|
| 4275 |
void Verifier::visitExtractValueInst(ExtractValueInst &EVI) { |
4275 |
void Verifier::visitExtractValueInst(ExtractValueInst &EVI) { |
| 4276 |
Check(ExtractValueInst::getIndexedType(EVI.getAggregateOperand()->getType(), |
4276 |
Check(ExtractValueInst::getIndexedType(EVI.getAggregateOperand()->getType(), |
| 4277 |
EVI.getIndices()) == EVI.getType(), |
4277 |
EVI.getIndices()) == EVI.getType(), |
| 4278 |
"Invalid ExtractValueInst operands!", &EVI); |
4278 |
"Invalid ExtractValueInst operands!", &EVI); |
| 4279 |
|
4279 |
|
| 4280 |
visitInstruction(EVI); |
4280 |
visitInstruction(EVI); |
| 4281 |
} |
4281 |
} |
| 4282 |
|
4282 |
|
| 4283 |
void Verifier::visitInsertValueInst(InsertValueInst &IVI) { |
4283 |
void Verifier::visitInsertValueInst(InsertValueInst &IVI) { |
| 4284 |
Check(ExtractValueInst::getIndexedType(IVI.getAggregateOperand()->getType(), |
4284 |
Check(ExtractValueInst::getIndexedType(IVI.getAggregateOperand()->getType(), |
| 4285 |
IVI.getIndices()) == |
4285 |
IVI.getIndices()) == |
| 4286 |
IVI.getOperand(1)->getType(), |
4286 |
IVI.getOperand(1)->getType(), |
| 4287 |
"Invalid InsertValueInst operands!", &IVI); |
4287 |
"Invalid InsertValueInst operands!", &IVI); |
| 4288 |
|
4288 |
|
| 4289 |
visitInstruction(IVI); |
4289 |
visitInstruction(IVI); |
| 4290 |
} |
4290 |
} |
| 4291 |
|
4291 |
|
| 4292 |
static Value *getParentPad(Value *EHPad) { |
4292 |
static Value *getParentPad(Value *EHPad) { |
| 4293 |
if (auto *FPI = dyn_cast(EHPad)) |
4293 |
if (auto *FPI = dyn_cast(EHPad)) |
| 4294 |
return FPI->getParentPad(); |
4294 |
return FPI->getParentPad(); |
| 4295 |
|
4295 |
|
| 4296 |
return cast(EHPad)->getParentPad(); |
4296 |
return cast(EHPad)->getParentPad(); |
| 4297 |
} |
4297 |
} |
| 4298 |
|
4298 |
|
| 4299 |
void Verifier::visitEHPadPredecessors(Instruction &I) { |
4299 |
void Verifier::visitEHPadPredecessors(Instruction &I) { |
| 4300 |
assert(I.isEHPad()); |
4300 |
assert(I.isEHPad()); |
| 4301 |
|
4301 |
|
| 4302 |
BasicBlock *BB = I.getParent(); |
4302 |
BasicBlock *BB = I.getParent(); |
| 4303 |
Function *F = BB->getParent(); |
4303 |
Function *F = BB->getParent(); |
| 4304 |
|
4304 |
|
| 4305 |
Check(BB != &F->getEntryBlock(), "EH pad cannot be in entry block.", &I); |
4305 |
Check(BB != &F->getEntryBlock(), "EH pad cannot be in entry block.", &I); |
| 4306 |
|
4306 |
|
| 4307 |
if (auto *LPI = dyn_cast(&I)) { |
4307 |
if (auto *LPI = dyn_cast(&I)) { |
| 4308 |
// The landingpad instruction defines its parent as a landing pad block. The |
4308 |
// The landingpad instruction defines its parent as a landing pad block. The |
| 4309 |
// landing pad block may be branched to only by the unwind edge of an |
4309 |
// landing pad block may be branched to only by the unwind edge of an |
| 4310 |
// invoke. |
4310 |
// invoke. |
| 4311 |
for (BasicBlock *PredBB : predecessors(BB)) { |
4311 |
for (BasicBlock *PredBB : predecessors(BB)) { |
| 4312 |
const auto *II = dyn_cast(PredBB->getTerminator()); |
4312 |
const auto *II = dyn_cast(PredBB->getTerminator()); |
| 4313 |
Check(II && II->getUnwindDest() == BB && II->getNormalDest() != BB, |
4313 |
Check(II && II->getUnwindDest() == BB && II->getNormalDest() != BB, |
| 4314 |
"Block containing LandingPadInst must be jumped to " |
4314 |
"Block containing LandingPadInst must be jumped to " |
| 4315 |
"only by the unwind edge of an invoke.", |
4315 |
"only by the unwind edge of an invoke.", |
| 4316 |
LPI); |
4316 |
LPI); |
| 4317 |
} |
4317 |
} |
| 4318 |
return; |
4318 |
return; |
| 4319 |
} |
4319 |
} |
| 4320 |
if (auto *CPI = dyn_cast(&I)) { |
4320 |
if (auto *CPI = dyn_cast(&I)) { |
| 4321 |
if (!pred_empty(BB)) |
4321 |
if (!pred_empty(BB)) |
| 4322 |
Check(BB->getUniquePredecessor() == CPI->getCatchSwitch()->getParent(), |
4322 |
Check(BB->getUniquePredecessor() == CPI->getCatchSwitch()->getParent(), |
| 4323 |
"Block containg CatchPadInst must be jumped to " |
4323 |
"Block containg CatchPadInst must be jumped to " |
| 4324 |
"only by its catchswitch.", |
4324 |
"only by its catchswitch.", |
| 4325 |
CPI); |
4325 |
CPI); |
| 4326 |
Check(BB != CPI->getCatchSwitch()->getUnwindDest(), |
4326 |
Check(BB != CPI->getCatchSwitch()->getUnwindDest(), |
| 4327 |
"Catchswitch cannot unwind to one of its catchpads", |
4327 |
"Catchswitch cannot unwind to one of its catchpads", |
| 4328 |
CPI->getCatchSwitch(), CPI); |
4328 |
CPI->getCatchSwitch(), CPI); |
| 4329 |
return; |
4329 |
return; |
| 4330 |
} |
4330 |
} |
| 4331 |
|
4331 |
|
| 4332 |
// Verify that each pred has a legal terminator with a legal to/from EH |
4332 |
// Verify that each pred has a legal terminator with a legal to/from EH |
| 4333 |
// pad relationship. |
4333 |
// pad relationship. |
| 4334 |
Instruction *ToPad = &I; |
4334 |
Instruction *ToPad = &I; |
| 4335 |
Value *ToPadParent = getParentPad(ToPad); |
4335 |
Value *ToPadParent = getParentPad(ToPad); |
| 4336 |
for (BasicBlock *PredBB : predecessors(BB)) { |
4336 |
for (BasicBlock *PredBB : predecessors(BB)) { |
| 4337 |
Instruction *TI = PredBB->getTerminator(); |
4337 |
Instruction *TI = PredBB->getTerminator(); |
| 4338 |
Value *FromPad; |
4338 |
Value *FromPad; |
| 4339 |
if (auto *II = dyn_cast(TI)) { |
4339 |
if (auto *II = dyn_cast(TI)) { |
| 4340 |
Check(II->getUnwindDest() == BB && II->getNormalDest() != BB, |
4340 |
Check(II->getUnwindDest() == BB && II->getNormalDest() != BB, |
| 4341 |
"EH pad must be jumped to via an unwind edge", ToPad, II); |
4341 |
"EH pad must be jumped to via an unwind edge", ToPad, II); |
| 4342 |
if (auto Bundle = II->getOperandBundle(LLVMContext::OB_funclet)) |
4342 |
if (auto Bundle = II->getOperandBundle(LLVMContext::OB_funclet)) |
| 4343 |
FromPad = Bundle->Inputs[0]; |
4343 |
FromPad = Bundle->Inputs[0]; |
| 4344 |
else |
4344 |
else |
| 4345 |
FromPad = ConstantTokenNone::get(II->getContext()); |
4345 |
FromPad = ConstantTokenNone::get(II->getContext()); |
| 4346 |
} else if (auto *CRI = dyn_cast(TI)) { |
4346 |
} else if (auto *CRI = dyn_cast(TI)) { |
| 4347 |
FromPad = CRI->getOperand(0); |
4347 |
FromPad = CRI->getOperand(0); |
| 4348 |
Check(FromPad != ToPadParent, "A cleanupret must exit its cleanup", CRI); |
4348 |
Check(FromPad != ToPadParent, "A cleanupret must exit its cleanup", CRI); |
| 4349 |
} else if (auto *CSI = dyn_cast(TI)) { |
4349 |
} else if (auto *CSI = dyn_cast(TI)) { |
| 4350 |
FromPad = CSI; |
4350 |
FromPad = CSI; |
| 4351 |
} else { |
4351 |
} else { |
| 4352 |
Check(false, "EH pad must be jumped to via an unwind edge", ToPad, TI); |
4352 |
Check(false, "EH pad must be jumped to via an unwind edge", ToPad, TI); |
| 4353 |
} |
4353 |
} |
| 4354 |
|
4354 |
|
| 4355 |
// The edge may exit from zero or more nested pads. |
4355 |
// The edge may exit from zero or more nested pads. |
| 4356 |
SmallSet Seen; |
4356 |
SmallSet Seen; |
| 4357 |
for (;; FromPad = getParentPad(FromPad)) { |
4357 |
for (;; FromPad = getParentPad(FromPad)) { |
| 4358 |
Check(FromPad != ToPad, |
4358 |
Check(FromPad != ToPad, |
| 4359 |
"EH pad cannot handle exceptions raised within it", FromPad, TI); |
4359 |
"EH pad cannot handle exceptions raised within it", FromPad, TI); |
| 4360 |
if (FromPad == ToPadParent) { |
4360 |
if (FromPad == ToPadParent) { |
| 4361 |
// This is a legal unwind edge. |
4361 |
// This is a legal unwind edge. |
| 4362 |
break; |
4362 |
break; |
| 4363 |
} |
4363 |
} |
| 4364 |
Check(!isa(FromPad), |
4364 |
Check(!isa(FromPad), |
| 4365 |
"A single unwind edge may only enter one EH pad", TI); |
4365 |
"A single unwind edge may only enter one EH pad", TI); |
| 4366 |
Check(Seen.insert(FromPad).second, "EH pad jumps through a cycle of pads", |
4366 |
Check(Seen.insert(FromPad).second, "EH pad jumps through a cycle of pads", |
| 4367 |
FromPad); |
4367 |
FromPad); |
| 4368 |
|
4368 |
|
| 4369 |
// This will be diagnosed on the corresponding instruction already. We |
4369 |
// This will be diagnosed on the corresponding instruction already. We |
| 4370 |
// need the extra check here to make sure getParentPad() works. |
4370 |
// need the extra check here to make sure getParentPad() works. |
| 4371 |
Check(isa(FromPad) || isa(FromPad), |
4371 |
Check(isa(FromPad) || isa(FromPad), |
| 4372 |
"Parent pad must be catchpad/cleanuppad/catchswitch", TI); |
4372 |
"Parent pad must be catchpad/cleanuppad/catchswitch", TI); |
| 4373 |
} |
4373 |
} |
| 4374 |
} |
4374 |
} |
| 4375 |
} |
4375 |
} |
| 4376 |
|
4376 |
|
| 4377 |
void Verifier::visitLandingPadInst(LandingPadInst &LPI) { |
4377 |
void Verifier::visitLandingPadInst(LandingPadInst &LPI) { |
| 4378 |
// The landingpad instruction is ill-formed if it doesn't have any clauses and |
4378 |
// The landingpad instruction is ill-formed if it doesn't have any clauses and |
| 4379 |
// isn't a cleanup. |
4379 |
// isn't a cleanup. |
| 4380 |
Check(LPI.getNumClauses() > 0 || LPI.isCleanup(), |
4380 |
Check(LPI.getNumClauses() > 0 || LPI.isCleanup(), |
| 4381 |
"LandingPadInst needs at least one clause or to be a cleanup.", &LPI); |
4381 |
"LandingPadInst needs at least one clause or to be a cleanup.", &LPI); |
| 4382 |
|
4382 |
|
| 4383 |
visitEHPadPredecessors(LPI); |
4383 |
visitEHPadPredecessors(LPI); |
| 4384 |
|
4384 |
|
| 4385 |
if (!LandingPadResultTy) |
4385 |
if (!LandingPadResultTy) |
| 4386 |
LandingPadResultTy = LPI.getType(); |
4386 |
LandingPadResultTy = LPI.getType(); |
| 4387 |
else |
4387 |
else |
| 4388 |
Check(LandingPadResultTy == LPI.getType(), |
4388 |
Check(LandingPadResultTy == LPI.getType(), |
| 4389 |
"The landingpad instruction should have a consistent result type " |
4389 |
"The landingpad instruction should have a consistent result type " |
| 4390 |
"inside a function.", |
4390 |
"inside a function.", |
| 4391 |
&LPI); |
4391 |
&LPI); |
| 4392 |
|
4392 |
|
| 4393 |
Function *F = LPI.getParent()->getParent(); |
4393 |
Function *F = LPI.getParent()->getParent(); |
| 4394 |
Check(F->hasPersonalityFn(), |
4394 |
Check(F->hasPersonalityFn(), |
| 4395 |
"LandingPadInst needs to be in a function with a personality.", &LPI); |
4395 |
"LandingPadInst needs to be in a function with a personality.", &LPI); |
| 4396 |
|
4396 |
|
| 4397 |
// The landingpad instruction must be the first non-PHI instruction in the |
4397 |
// The landingpad instruction must be the first non-PHI instruction in the |
| 4398 |
// block. |
4398 |
// block. |
| 4399 |
Check(LPI.getParent()->getLandingPadInst() == &LPI, |
4399 |
Check(LPI.getParent()->getLandingPadInst() == &LPI, |
| 4400 |
"LandingPadInst not the first non-PHI instruction in the block.", &LPI); |
4400 |
"LandingPadInst not the first non-PHI instruction in the block.", &LPI); |
| 4401 |
|
4401 |
|
| 4402 |
for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) { |
4402 |
for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) { |
| 4403 |
Constant *Clause = LPI.getClause(i); |
4403 |
Constant *Clause = LPI.getClause(i); |
| 4404 |
if (LPI.isCatch(i)) { |
4404 |
if (LPI.isCatch(i)) { |
| 4405 |
Check(isa(Clause->getType()), |
4405 |
Check(isa(Clause->getType()), |
| 4406 |
"Catch operand does not have pointer type!", &LPI); |
4406 |
"Catch operand does not have pointer type!", &LPI); |
| 4407 |
} else { |
4407 |
} else { |
| 4408 |
Check(LPI.isFilter(i), "Clause is neither catch nor filter!", &LPI); |
4408 |
Check(LPI.isFilter(i), "Clause is neither catch nor filter!", &LPI); |
| 4409 |
Check(isa(Clause) || isa(Clause), |
4409 |
Check(isa(Clause) || isa(Clause), |
| 4410 |
"Filter operand is not an array of constants!", &LPI); |
4410 |
"Filter operand is not an array of constants!", &LPI); |
| 4411 |
} |
4411 |
} |
| 4412 |
} |
4412 |
} |
| 4413 |
|
4413 |
|
| 4414 |
visitInstruction(LPI); |
4414 |
visitInstruction(LPI); |
| 4415 |
} |
4415 |
} |
| 4416 |
|
4416 |
|
| 4417 |
void Verifier::visitResumeInst(ResumeInst &RI) { |
4417 |
void Verifier::visitResumeInst(ResumeInst &RI) { |
| 4418 |
Check(RI.getFunction()->hasPersonalityFn(), |
4418 |
Check(RI.getFunction()->hasPersonalityFn(), |
| 4419 |
"ResumeInst needs to be in a function with a personality.", &RI); |
4419 |
"ResumeInst needs to be in a function with a personality.", &RI); |
| 4420 |
|
4420 |
|
| 4421 |
if (!LandingPadResultTy) |
4421 |
if (!LandingPadResultTy) |
| 4422 |
LandingPadResultTy = RI.getValue()->getType(); |
4422 |
LandingPadResultTy = RI.getValue()->getType(); |
| 4423 |
else |
4423 |
else |
| 4424 |
Check(LandingPadResultTy == RI.getValue()->getType(), |
4424 |
Check(LandingPadResultTy == RI.getValue()->getType(), |
| 4425 |
"The resume instruction should have a consistent result type " |
4425 |
"The resume instruction should have a consistent result type " |
| 4426 |
"inside a function.", |
4426 |
"inside a function.", |
| 4427 |
&RI); |
4427 |
&RI); |
| 4428 |
|
4428 |
|
| 4429 |
visitTerminator(RI); |
4429 |
visitTerminator(RI); |
| 4430 |
} |
4430 |
} |
| 4431 |
|
4431 |
|
| 4432 |
void Verifier::visitCatchPadInst(CatchPadInst &CPI) { |
4432 |
void Verifier::visitCatchPadInst(CatchPadInst &CPI) { |
| 4433 |
BasicBlock *BB = CPI.getParent(); |
4433 |
BasicBlock *BB = CPI.getParent(); |
| 4434 |
|
4434 |
|
| 4435 |
Function *F = BB->getParent(); |
4435 |
Function *F = BB->getParent(); |
| 4436 |
Check(F->hasPersonalityFn(), |
4436 |
Check(F->hasPersonalityFn(), |
| 4437 |
"CatchPadInst needs to be in a function with a personality.", &CPI); |
4437 |
"CatchPadInst needs to be in a function with a personality.", &CPI); |
| 4438 |
|
4438 |
|
| 4439 |
Check(isa(CPI.getParentPad()), |
4439 |
Check(isa(CPI.getParentPad()), |
| 4440 |
"CatchPadInst needs to be directly nested in a CatchSwitchInst.", |
4440 |
"CatchPadInst needs to be directly nested in a CatchSwitchInst.", |
| 4441 |
CPI.getParentPad()); |
4441 |
CPI.getParentPad()); |
| 4442 |
|
4442 |
|
| 4443 |
// The catchpad instruction must be the first non-PHI instruction in the |
4443 |
// The catchpad instruction must be the first non-PHI instruction in the |
| 4444 |
// block. |
4444 |
// block. |
| 4445 |
Check(BB->getFirstNonPHI() == &CPI, |
4445 |
Check(BB->getFirstNonPHI() == &CPI, |
| 4446 |
"CatchPadInst not the first non-PHI instruction in the block.", &CPI); |
4446 |
"CatchPadInst not the first non-PHI instruction in the block.", &CPI); |
| 4447 |
|
4447 |
|
| 4448 |
visitEHPadPredecessors(CPI); |
4448 |
visitEHPadPredecessors(CPI); |
| 4449 |
visitFuncletPadInst(CPI); |
4449 |
visitFuncletPadInst(CPI); |
| 4450 |
} |
4450 |
} |
| 4451 |
|
4451 |
|
| 4452 |
void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) { |
4452 |
void Verifier::visitCatchReturnInst(CatchReturnInst &CatchReturn) { |
| 4453 |
Check(isa(CatchReturn.getOperand(0)), |
4453 |
Check(isa(CatchReturn.getOperand(0)), |
| 4454 |
"CatchReturnInst needs to be provided a CatchPad", &CatchReturn, |
4454 |
"CatchReturnInst needs to be provided a CatchPad", &CatchReturn, |
| 4455 |
CatchReturn.getOperand(0)); |
4455 |
CatchReturn.getOperand(0)); |
| 4456 |
|
4456 |
|
| 4457 |
visitTerminator(CatchReturn); |
4457 |
visitTerminator(CatchReturn); |
| 4458 |
} |
4458 |
} |
| 4459 |
|
4459 |
|
| 4460 |
void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) { |
4460 |
void Verifier::visitCleanupPadInst(CleanupPadInst &CPI) { |
| 4461 |
BasicBlock *BB = CPI.getParent(); |
4461 |
BasicBlock *BB = CPI.getParent(); |
| 4462 |
|
4462 |
|
| 4463 |
Function *F = BB->getParent(); |
4463 |
Function *F = BB->getParent(); |
| 4464 |
Check(F->hasPersonalityFn(), |
4464 |
Check(F->hasPersonalityFn(), |
| 4465 |
"CleanupPadInst needs to be in a function with a personality.", &CPI); |
4465 |
"CleanupPadInst needs to be in a function with a personality.", &CPI); |
| 4466 |
|
4466 |
|
| 4467 |
// The cleanuppad instruction must be the first non-PHI instruction in the |
4467 |
// The cleanuppad instruction must be the first non-PHI instruction in the |
| 4468 |
// block. |
4468 |
// block. |
| 4469 |
Check(BB->getFirstNonPHI() == &CPI, |
4469 |
Check(BB->getFirstNonPHI() == &CPI, |
| 4470 |
"CleanupPadInst not the first non-PHI instruction in the block.", &CPI); |
4470 |
"CleanupPadInst not the first non-PHI instruction in the block.", &CPI); |
| 4471 |
|
4471 |
|
| 4472 |
auto *ParentPad = CPI.getParentPad(); |
4472 |
auto *ParentPad = CPI.getParentPad(); |
| 4473 |
Check(isa(ParentPad) || isa(ParentPad), |
4473 |
Check(isa(ParentPad) || isa(ParentPad), |
| 4474 |
"CleanupPadInst has an invalid parent.", &CPI); |
4474 |
"CleanupPadInst has an invalid parent.", &CPI); |
| 4475 |
|
4475 |
|
| 4476 |
visitEHPadPredecessors(CPI); |
4476 |
visitEHPadPredecessors(CPI); |
| 4477 |
visitFuncletPadInst(CPI); |
4477 |
visitFuncletPadInst(CPI); |
| 4478 |
} |
4478 |
} |
| 4479 |
|
4479 |
|
| 4480 |
void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) { |
4480 |
void Verifier::visitFuncletPadInst(FuncletPadInst &FPI) { |
| 4481 |
User *FirstUser = nullptr; |
4481 |
User *FirstUser = nullptr; |
| 4482 |
Value *FirstUnwindPad = nullptr; |
4482 |
Value *FirstUnwindPad = nullptr; |
| 4483 |
SmallVector Worklist({&FPI}); |
4483 |
SmallVector Worklist({&FPI}); |
| 4484 |
SmallSet Seen; |
4484 |
SmallSet Seen; |
| 4485 |
|
4485 |
|
| 4486 |
while (!Worklist.empty()) { |
4486 |
while (!Worklist.empty()) { |
| 4487 |
FuncletPadInst *CurrentPad = Worklist.pop_back_val(); |
4487 |
FuncletPadInst *CurrentPad = Worklist.pop_back_val(); |
| 4488 |
Check(Seen.insert(CurrentPad).second, |
4488 |
Check(Seen.insert(CurrentPad).second, |
| 4489 |
"FuncletPadInst must not be nested within itself", CurrentPad); |
4489 |
"FuncletPadInst must not be nested within itself", CurrentPad); |
| 4490 |
Value *UnresolvedAncestorPad = nullptr; |
4490 |
Value *UnresolvedAncestorPad = nullptr; |
| 4491 |
for (User *U : CurrentPad->users()) { |
4491 |
for (User *U : CurrentPad->users()) { |
| 4492 |
BasicBlock *UnwindDest; |
4492 |
BasicBlock *UnwindDest; |
| 4493 |
if (auto *CRI = dyn_cast(U)) { |
4493 |
if (auto *CRI = dyn_cast(U)) { |
| 4494 |
UnwindDest = CRI->getUnwindDest(); |
4494 |
UnwindDest = CRI->getUnwindDest(); |
| 4495 |
} else if (auto *CSI = dyn_cast(U)) { |
4495 |
} else if (auto *CSI = dyn_cast(U)) { |
| 4496 |
// We allow catchswitch unwind to caller to nest |
4496 |
// We allow catchswitch unwind to caller to nest |
| 4497 |
// within an outer pad that unwinds somewhere else, |
4497 |
// within an outer pad that unwinds somewhere else, |
| 4498 |
// because catchswitch doesn't have a nounwind variant. |
4498 |
// because catchswitch doesn't have a nounwind variant. |
| 4499 |
// See e.g. SimplifyCFGOpt::SimplifyUnreachable. |
4499 |
// See e.g. SimplifyCFGOpt::SimplifyUnreachable. |
| 4500 |
if (CSI->unwindsToCaller()) |
4500 |
if (CSI->unwindsToCaller()) |
| 4501 |
continue; |
4501 |
continue; |
| 4502 |
UnwindDest = CSI->getUnwindDest(); |
4502 |
UnwindDest = CSI->getUnwindDest(); |
| 4503 |
} else if (auto *II = dyn_cast(U)) { |
4503 |
} else if (auto *II = dyn_cast(U)) { |
| 4504 |
UnwindDest = II->getUnwindDest(); |
4504 |
UnwindDest = II->getUnwindDest(); |
| 4505 |
} else if (isa(U)) { |
4505 |
} else if (isa(U)) { |
| 4506 |
// Calls which don't unwind may be found inside funclet |
4506 |
// Calls which don't unwind may be found inside funclet |
| 4507 |
// pads that unwind somewhere else. We don't *require* |
4507 |
// pads that unwind somewhere else. We don't *require* |
| 4508 |
// such calls to be annotated nounwind. |
4508 |
// such calls to be annotated nounwind. |
| 4509 |
continue; |
4509 |
continue; |
| 4510 |
} else if (auto *CPI = dyn_cast(U)) { |
4510 |
} else if (auto *CPI = dyn_cast(U)) { |
| 4511 |
// The unwind dest for a cleanup can only be found by |
4511 |
// The unwind dest for a cleanup can only be found by |
| 4512 |
// recursive search. Add it to the worklist, and we'll |
4512 |
// recursive search. Add it to the worklist, and we'll |
| 4513 |
// search for its first use that determines where it unwinds. |
4513 |
// search for its first use that determines where it unwinds. |
| 4514 |
Worklist.push_back(CPI); |
4514 |
Worklist.push_back(CPI); |
| 4515 |
continue; |
4515 |
continue; |
| 4516 |
} else { |
4516 |
} else { |
| 4517 |
Check(isa(U), "Bogus funclet pad use", U); |
4517 |
Check(isa(U), "Bogus funclet pad use", U); |
| 4518 |
continue; |
4518 |
continue; |
| 4519 |
} |
4519 |
} |
| 4520 |
|
4520 |
|
| 4521 |
Value *UnwindPad; |
4521 |
Value *UnwindPad; |
| 4522 |
bool ExitsFPI; |
4522 |
bool ExitsFPI; |
| 4523 |
if (UnwindDest) { |
4523 |
if (UnwindDest) { |
| 4524 |
UnwindPad = UnwindDest->getFirstNonPHI(); |
4524 |
UnwindPad = UnwindDest->getFirstNonPHI(); |
| 4525 |
if (!cast(UnwindPad)->isEHPad()) |
4525 |
if (!cast(UnwindPad)->isEHPad()) |
| 4526 |
continue; |
4526 |
continue; |
| 4527 |
Value *UnwindParent = getParentPad(UnwindPad); |
4527 |
Value *UnwindParent = getParentPad(UnwindPad); |
| 4528 |
// Ignore unwind edges that don't exit CurrentPad. |
4528 |
// Ignore unwind edges that don't exit CurrentPad. |
| 4529 |
if (UnwindParent == CurrentPad) |
4529 |
if (UnwindParent == CurrentPad) |
| 4530 |
continue; |
4530 |
continue; |
| 4531 |
// Determine whether the original funclet pad is exited, |
4531 |
// Determine whether the original funclet pad is exited, |
| 4532 |
// and if we are scanning nested pads determine how many |
4532 |
// and if we are scanning nested pads determine how many |
| 4533 |
// of them are exited so we can stop searching their |
4533 |
// of them are exited so we can stop searching their |
| 4534 |
// children. |
4534 |
// children. |
| 4535 |
Value *ExitedPad = CurrentPad; |
4535 |
Value *ExitedPad = CurrentPad; |
| 4536 |
ExitsFPI = false; |
4536 |
ExitsFPI = false; |
| 4537 |
do { |
4537 |
do { |
| 4538 |
if (ExitedPad == &FPI) { |
4538 |
if (ExitedPad == &FPI) { |
| 4539 |
ExitsFPI = true; |
4539 |
ExitsFPI = true; |
| 4540 |
// Now we can resolve any ancestors of CurrentPad up to |
4540 |
// Now we can resolve any ancestors of CurrentPad up to |
| 4541 |
// FPI, but not including FPI since we need to make sure |
4541 |
// FPI, but not including FPI since we need to make sure |
| 4542 |
// to check all direct users of FPI for consistency. |
4542 |
// to check all direct users of FPI for consistency. |
| 4543 |
UnresolvedAncestorPad = &FPI; |
4543 |
UnresolvedAncestorPad = &FPI; |
| 4544 |
break; |
4544 |
break; |
| 4545 |
} |
4545 |
} |
| 4546 |
Value *ExitedParent = getParentPad(ExitedPad); |
4546 |
Value *ExitedParent = getParentPad(ExitedPad); |
| 4547 |
if (ExitedParent == UnwindParent) { |
4547 |
if (ExitedParent == UnwindParent) { |
| 4548 |
// ExitedPad is the ancestor-most pad which this unwind |
4548 |
// ExitedPad is the ancestor-most pad which this unwind |
| 4549 |
// edge exits, so we can resolve up to it, meaning that |
4549 |
// edge exits, so we can resolve up to it, meaning that |
| 4550 |
// ExitedParent is the first ancestor still unresolved. |
4550 |
// ExitedParent is the first ancestor still unresolved. |
| 4551 |
UnresolvedAncestorPad = ExitedParent; |
4551 |
UnresolvedAncestorPad = ExitedParent; |
| 4552 |
break; |
4552 |
break; |
| 4553 |
} |
4553 |
} |
| 4554 |
ExitedPad = ExitedParent; |
4554 |
ExitedPad = ExitedParent; |
| 4555 |
} while (!isa(ExitedPad)); |
4555 |
} while (!isa(ExitedPad)); |
| 4556 |
} else { |
4556 |
} else { |
| 4557 |
// Unwinding to caller exits all pads. |
4557 |
// Unwinding to caller exits all pads. |
| 4558 |
UnwindPad = ConstantTokenNone::get(FPI.getContext()); |
4558 |
UnwindPad = ConstantTokenNone::get(FPI.getContext()); |
| 4559 |
ExitsFPI = true; |
4559 |
ExitsFPI = true; |
| 4560 |
UnresolvedAncestorPad = &FPI; |
4560 |
UnresolvedAncestorPad = &FPI; |
| 4561 |
} |
4561 |
} |
| 4562 |
|
4562 |
|
| 4563 |
if (ExitsFPI) { |
4563 |
if (ExitsFPI) { |
| 4564 |
// This unwind edge exits FPI. Make sure it agrees with other |
4564 |
// This unwind edge exits FPI. Make sure it agrees with other |
| 4565 |
// such edges. |
4565 |
// such edges. |
| 4566 |
if (FirstUser) { |
4566 |
if (FirstUser) { |
| 4567 |
Check(UnwindPad == FirstUnwindPad, |
4567 |
Check(UnwindPad == FirstUnwindPad, |
| 4568 |
"Unwind edges out of a funclet " |
4568 |
"Unwind edges out of a funclet " |
| 4569 |
"pad must have the same unwind " |
4569 |
"pad must have the same unwind " |
| 4570 |
"dest", |
4570 |
"dest", |
| 4571 |
&FPI, U, FirstUser); |
4571 |
&FPI, U, FirstUser); |
| 4572 |
} else { |
4572 |
} else { |
| 4573 |
FirstUser = U; |
4573 |
FirstUser = U; |
| 4574 |
FirstUnwindPad = UnwindPad; |
4574 |
FirstUnwindPad = UnwindPad; |
| 4575 |
// Record cleanup sibling unwinds for verifySiblingFuncletUnwinds |
4575 |
// Record cleanup sibling unwinds for verifySiblingFuncletUnwinds |
| 4576 |
if (isa(&FPI) && !isa(UnwindPad) && |
4576 |
if (isa(&FPI) && !isa(UnwindPad) && |
| 4577 |
getParentPad(UnwindPad) == getParentPad(&FPI)) |
4577 |
getParentPad(UnwindPad) == getParentPad(&FPI)) |
| 4578 |
SiblingFuncletInfo[&FPI] = cast(U); |
4578 |
SiblingFuncletInfo[&FPI] = cast(U); |
| 4579 |
} |
4579 |
} |
| 4580 |
} |
4580 |
} |
| 4581 |
// Make sure we visit all uses of FPI, but for nested pads stop as |
4581 |
// Make sure we visit all uses of FPI, but for nested pads stop as |
| 4582 |
// soon as we know where they unwind to. |
4582 |
// soon as we know where they unwind to. |
| 4583 |
if (CurrentPad != &FPI) |
4583 |
if (CurrentPad != &FPI) |
| 4584 |
break; |
4584 |
break; |
| 4585 |
} |
4585 |
} |
| 4586 |
if (UnresolvedAncestorPad) { |
4586 |
if (UnresolvedAncestorPad) { |
| 4587 |
if (CurrentPad == UnresolvedAncestorPad) { |
4587 |
if (CurrentPad == UnresolvedAncestorPad) { |
| 4588 |
// When CurrentPad is FPI itself, we don't mark it as resolved even if |
4588 |
// When CurrentPad is FPI itself, we don't mark it as resolved even if |
| 4589 |
// we've found an unwind edge that exits it, because we need to verify |
4589 |
// we've found an unwind edge that exits it, because we need to verify |
| 4590 |
// all direct uses of FPI. |
4590 |
// all direct uses of FPI. |
| 4591 |
assert(CurrentPad == &FPI); |
4591 |
assert(CurrentPad == &FPI); |
| 4592 |
continue; |
4592 |
continue; |
| 4593 |
} |
4593 |
} |
| 4594 |
// Pop off the worklist any nested pads that we've found an unwind |
4594 |
// Pop off the worklist any nested pads that we've found an unwind |
| 4595 |
// destination for. The pads on the worklist are the uncles, |
4595 |
// destination for. The pads on the worklist are the uncles, |
| 4596 |
// great-uncles, etc. of CurrentPad. We've found an unwind destination |
4596 |
// great-uncles, etc. of CurrentPad. We've found an unwind destination |
| 4597 |
// for all ancestors of CurrentPad up to but not including |
4597 |
// for all ancestors of CurrentPad up to but not including |
| 4598 |
// UnresolvedAncestorPad. |
4598 |
// UnresolvedAncestorPad. |
| 4599 |
Value *ResolvedPad = CurrentPad; |
4599 |
Value *ResolvedPad = CurrentPad; |
| 4600 |
while (!Worklist.empty()) { |
4600 |
while (!Worklist.empty()) { |
| 4601 |
Value *UnclePad = Worklist.back(); |
4601 |
Value *UnclePad = Worklist.back(); |
| 4602 |
Value *AncestorPad = getParentPad(UnclePad); |
4602 |
Value *AncestorPad = getParentPad(UnclePad); |
| 4603 |
// Walk ResolvedPad up the ancestor list until we either find the |
4603 |
// Walk ResolvedPad up the ancestor list until we either find the |
| 4604 |
// uncle's parent or the last resolved ancestor. |
4604 |
// uncle's parent or the last resolved ancestor. |
| 4605 |
while (ResolvedPad != AncestorPad) { |
4605 |
while (ResolvedPad != AncestorPad) { |
| 4606 |
Value *ResolvedParent = getParentPad(ResolvedPad); |
4606 |
Value *ResolvedParent = getParentPad(ResolvedPad); |
| 4607 |
if (ResolvedParent == UnresolvedAncestorPad) { |
4607 |
if (ResolvedParent == UnresolvedAncestorPad) { |
| 4608 |
break; |
4608 |
break; |
| 4609 |
} |
4609 |
} |
| 4610 |
ResolvedPad = ResolvedParent; |
4610 |
ResolvedPad = ResolvedParent; |
| 4611 |
} |
4611 |
} |
| 4612 |
// If the resolved ancestor search didn't find the uncle's parent, |
4612 |
// If the resolved ancestor search didn't find the uncle's parent, |
| 4613 |
// then the uncle is not yet resolved. |
4613 |
// then the uncle is not yet resolved. |
| 4614 |
if (ResolvedPad != AncestorPad) |
4614 |
if (ResolvedPad != AncestorPad) |
| 4615 |
break; |
4615 |
break; |
| 4616 |
// This uncle is resolved, so pop it from the worklist. |
4616 |
// This uncle is resolved, so pop it from the worklist. |
| 4617 |
Worklist.pop_back(); |
4617 |
Worklist.pop_back(); |
| 4618 |
} |
4618 |
} |
| 4619 |
} |
4619 |
} |
| 4620 |
} |
4620 |
} |
| 4621 |
|
4621 |
|
| 4622 |
if (FirstUnwindPad) { |
4622 |
if (FirstUnwindPad) { |
| 4623 |
if (auto *CatchSwitch = dyn_cast(FPI.getParentPad())) { |
4623 |
if (auto *CatchSwitch = dyn_cast(FPI.getParentPad())) { |
| 4624 |
BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest(); |
4624 |
BasicBlock *SwitchUnwindDest = CatchSwitch->getUnwindDest(); |
| 4625 |
Value *SwitchUnwindPad; |
4625 |
Value *SwitchUnwindPad; |
| 4626 |
if (SwitchUnwindDest) |
4626 |
if (SwitchUnwindDest) |
| 4627 |
SwitchUnwindPad = SwitchUnwindDest->getFirstNonPHI(); |
4627 |
SwitchUnwindPad = SwitchUnwindDest->getFirstNonPHI(); |
| 4628 |
else |
4628 |
else |
| 4629 |
SwitchUnwindPad = ConstantTokenNone::get(FPI.getContext()); |
4629 |
SwitchUnwindPad = ConstantTokenNone::get(FPI.getContext()); |
| 4630 |
Check(SwitchUnwindPad == FirstUnwindPad, |
4630 |
Check(SwitchUnwindPad == FirstUnwindPad, |
| 4631 |
"Unwind edges out of a catch must have the same unwind dest as " |
4631 |
"Unwind edges out of a catch must have the same unwind dest as " |
| 4632 |
"the parent catchswitch", |
4632 |
"the parent catchswitch", |
| 4633 |
&FPI, FirstUser, CatchSwitch); |
4633 |
&FPI, FirstUser, CatchSwitch); |
| 4634 |
} |
4634 |
} |
| 4635 |
} |
4635 |
} |
| 4636 |
|
4636 |
|
| 4637 |
visitInstruction(FPI); |
4637 |
visitInstruction(FPI); |
| 4638 |
} |
4638 |
} |
| 4639 |
|
4639 |
|
| 4640 |
void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) { |
4640 |
void Verifier::visitCatchSwitchInst(CatchSwitchInst &CatchSwitch) { |
| 4641 |
BasicBlock *BB = CatchSwitch.getParent(); |
4641 |
BasicBlock *BB = CatchSwitch.getParent(); |
| 4642 |
|
4642 |
|
| 4643 |
Function *F = BB->getParent(); |
4643 |
Function *F = BB->getParent(); |
| 4644 |
Check(F->hasPersonalityFn(), |
4644 |
Check(F->hasPersonalityFn(), |
| 4645 |
"CatchSwitchInst needs to be in a function with a personality.", |
4645 |
"CatchSwitchInst needs to be in a function with a personality.", |
| 4646 |
&CatchSwitch); |
4646 |
&CatchSwitch); |
| 4647 |
|
4647 |
|
| 4648 |
// The catchswitch instruction must be the first non-PHI instruction in the |
4648 |
// The catchswitch instruction must be the first non-PHI instruction in the |
| 4649 |
// block. |
4649 |
// block. |
| 4650 |
Check(BB->getFirstNonPHI() == &CatchSwitch, |
4650 |
Check(BB->getFirstNonPHI() == &CatchSwitch, |
| 4651 |
"CatchSwitchInst not the first non-PHI instruction in the block.", |
4651 |
"CatchSwitchInst not the first non-PHI instruction in the block.", |
| 4652 |
&CatchSwitch); |
4652 |
&CatchSwitch); |
| 4653 |
|
4653 |
|
| 4654 |
auto *ParentPad = CatchSwitch.getParentPad(); |
4654 |
auto *ParentPad = CatchSwitch.getParentPad(); |
| 4655 |
Check(isa(ParentPad) || isa(ParentPad), |
4655 |
Check(isa(ParentPad) || isa(ParentPad), |
| 4656 |
"CatchSwitchInst has an invalid parent.", ParentPad); |
4656 |
"CatchSwitchInst has an invalid parent.", ParentPad); |
| 4657 |
|
4657 |
|
| 4658 |
if (BasicBlock *UnwindDest = CatchSwitch.getUnwindDest()) { |
4658 |
if (BasicBlock *UnwindDest = CatchSwitch.getUnwindDest()) { |
| 4659 |
Instruction *I = UnwindDest->getFirstNonPHI(); |
4659 |
Instruction *I = UnwindDest->getFirstNonPHI(); |
| 4660 |
Check(I->isEHPad() && !isa(I), |
4660 |
Check(I->isEHPad() && !isa(I), |
| 4661 |
"CatchSwitchInst must unwind to an EH block which is not a " |
4661 |
"CatchSwitchInst must unwind to an EH block which is not a " |
| 4662 |
"landingpad.", |
4662 |
"landingpad.", |
| 4663 |
&CatchSwitch); |
4663 |
&CatchSwitch); |
| 4664 |
|
4664 |
|
| 4665 |
// Record catchswitch sibling unwinds for verifySiblingFuncletUnwinds |
4665 |
// Record catchswitch sibling unwinds for verifySiblingFuncletUnwinds |
| 4666 |
if (getParentPad(I) == ParentPad) |
4666 |
if (getParentPad(I) == ParentPad) |
| 4667 |
SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch; |
4667 |
SiblingFuncletInfo[&CatchSwitch] = &CatchSwitch; |
| 4668 |
} |
4668 |
} |
| 4669 |
|
4669 |
|
| 4670 |
Check(CatchSwitch.getNumHandlers() != 0, |
4670 |
Check(CatchSwitch.getNumHandlers() != 0, |
| 4671 |
"CatchSwitchInst cannot have empty handler list", &CatchSwitch); |
4671 |
"CatchSwitchInst cannot have empty handler list", &CatchSwitch); |
| 4672 |
|
4672 |
|
| 4673 |
for (BasicBlock *Handler : CatchSwitch.handlers()) { |
4673 |
for (BasicBlock *Handler : CatchSwitch.handlers()) { |
| 4674 |
Check(isa(Handler->getFirstNonPHI()), |
4674 |
Check(isa(Handler->getFirstNonPHI()), |
| 4675 |
"CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler); |
4675 |
"CatchSwitchInst handlers must be catchpads", &CatchSwitch, Handler); |
| 4676 |
} |
4676 |
} |
| 4677 |
|
4677 |
|
| 4678 |
visitEHPadPredecessors(CatchSwitch); |
4678 |
visitEHPadPredecessors(CatchSwitch); |
| 4679 |
visitTerminator(CatchSwitch); |
4679 |
visitTerminator(CatchSwitch); |
| 4680 |
} |
4680 |
} |
| 4681 |
|
4681 |
|
| 4682 |
void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) { |
4682 |
void Verifier::visitCleanupReturnInst(CleanupReturnInst &CRI) { |
| 4683 |
Check(isa(CRI.getOperand(0)), |
4683 |
Check(isa(CRI.getOperand(0)), |
| 4684 |
"CleanupReturnInst needs to be provided a CleanupPad", &CRI, |
4684 |
"CleanupReturnInst needs to be provided a CleanupPad", &CRI, |
| 4685 |
CRI.getOperand(0)); |
4685 |
CRI.getOperand(0)); |
| 4686 |
|
4686 |
|
| 4687 |
if (BasicBlock *UnwindDest = CRI.getUnwindDest()) { |
4687 |
if (BasicBlock *UnwindDest = CRI.getUnwindDest()) { |
| 4688 |
Instruction *I = UnwindDest->getFirstNonPHI(); |
4688 |
Instruction *I = UnwindDest->getFirstNonPHI(); |
| 4689 |
Check(I->isEHPad() && !isa(I), |
4689 |
Check(I->isEHPad() && !isa(I), |
| 4690 |
"CleanupReturnInst must unwind to an EH block which is not a " |
4690 |
"CleanupReturnInst must unwind to an EH block which is not a " |
| 4691 |
"landingpad.", |
4691 |
"landingpad.", |
| 4692 |
&CRI); |
4692 |
&CRI); |
| 4693 |
} |
4693 |
} |
| 4694 |
|
4694 |
|
| 4695 |
visitTerminator(CRI); |
4695 |
visitTerminator(CRI); |
| 4696 |
} |
4696 |
} |
| 4697 |
|
4697 |
|
| 4698 |
void Verifier::verifyDominatesUse(Instruction &I, unsigned i) { |
4698 |
void Verifier::verifyDominatesUse(Instruction &I, unsigned i) { |
| 4699 |
Instruction *Op = cast(I.getOperand(i)); |
4699 |
Instruction *Op = cast(I.getOperand(i)); |
| 4700 |
// If the we have an invalid invoke, don't try to compute the dominance. |
4700 |
// If the we have an invalid invoke, don't try to compute the dominance. |
| 4701 |
// We already reject it in the invoke specific checks and the dominance |
4701 |
// We already reject it in the invoke specific checks and the dominance |
| 4702 |
// computation doesn't handle multiple edges. |
4702 |
// computation doesn't handle multiple edges. |
| 4703 |
if (InvokeInst *II = dyn_cast(Op)) { |
4703 |
if (InvokeInst *II = dyn_cast(Op)) { |
| 4704 |
if (II->getNormalDest() == II->getUnwindDest()) |
4704 |
if (II->getNormalDest() == II->getUnwindDest()) |
| 4705 |
return; |
4705 |
return; |
| 4706 |
} |
4706 |
} |
| 4707 |
|
4707 |
|
| 4708 |
// Quick check whether the def has already been encountered in the same block. |
4708 |
// Quick check whether the def has already been encountered in the same block. |
| 4709 |
// PHI nodes are not checked to prevent accepting preceding PHIs, because PHI |
4709 |
// PHI nodes are not checked to prevent accepting preceding PHIs, because PHI |
| 4710 |
// uses are defined to happen on the incoming edge, not at the instruction. |
4710 |
// uses are defined to happen on the incoming edge, not at the instruction. |
| 4711 |
// |
4711 |
// |
| 4712 |
// FIXME: If this operand is a MetadataAsValue (wrapping a LocalAsMetadata) |
4712 |
// FIXME: If this operand is a MetadataAsValue (wrapping a LocalAsMetadata) |
| 4713 |
// wrapping an SSA value, assert that we've already encountered it. See |
4713 |
// wrapping an SSA value, assert that we've already encountered it. See |
| 4714 |
// related FIXME in Mapper::mapLocalAsMetadata in ValueMapper.cpp. |
4714 |
// related FIXME in Mapper::mapLocalAsMetadata in ValueMapper.cpp. |
| 4715 |
if (!isa(I) && InstsInThisBlock.count(Op)) |
4715 |
if (!isa(I) && InstsInThisBlock.count(Op)) |
| 4716 |
return; |
4716 |
return; |
| 4717 |
|
4717 |
|
| 4718 |
const Use &U = I.getOperandUse(i); |
4718 |
const Use &U = I.getOperandUse(i); |
| 4719 |
Check(DT.dominates(Op, U), "Instruction does not dominate all uses!", Op, &I); |
4719 |
Check(DT.dominates(Op, U), "Instruction does not dominate all uses!", Op, &I); |
| 4720 |
} |
4720 |
} |
| 4721 |
|
4721 |
|
| 4722 |
void Verifier::visitDereferenceableMetadata(Instruction& I, MDNode* MD) { |
4722 |
void Verifier::visitDereferenceableMetadata(Instruction& I, MDNode* MD) { |
| 4723 |
Check(I.getType()->isPointerTy(), |
4723 |
Check(I.getType()->isPointerTy(), |
| 4724 |
"dereferenceable, dereferenceable_or_null " |
4724 |
"dereferenceable, dereferenceable_or_null " |
| 4725 |
"apply only to pointer types", |
4725 |
"apply only to pointer types", |
| 4726 |
&I); |
4726 |
&I); |
| 4727 |
Check((isa(I) || isa(I)), |
4727 |
Check((isa(I) || isa(I)), |
| 4728 |
"dereferenceable, dereferenceable_or_null apply only to load" |
4728 |
"dereferenceable, dereferenceable_or_null apply only to load" |
| 4729 |
" and inttoptr instructions, use attributes for calls or invokes", |
4729 |
" and inttoptr instructions, use attributes for calls or invokes", |
| 4730 |
&I); |
4730 |
&I); |
| 4731 |
Check(MD->getNumOperands() == 1, |
4731 |
Check(MD->getNumOperands() == 1, |
| 4732 |
"dereferenceable, dereferenceable_or_null " |
4732 |
"dereferenceable, dereferenceable_or_null " |
| 4733 |
"take one operand!", |
4733 |
"take one operand!", |
| 4734 |
&I); |
4734 |
&I); |
| 4735 |
ConstantInt *CI = mdconst::dyn_extract(MD->getOperand(0)); |
4735 |
ConstantInt *CI = mdconst::dyn_extract(MD->getOperand(0)); |
| 4736 |
Check(CI && CI->getType()->isIntegerTy(64), |
4736 |
Check(CI && CI->getType()->isIntegerTy(64), |
| 4737 |
"dereferenceable, " |
4737 |
"dereferenceable, " |
| 4738 |
"dereferenceable_or_null metadata value must be an i64!", |
4738 |
"dereferenceable_or_null metadata value must be an i64!", |
| 4739 |
&I); |
4739 |
&I); |
| 4740 |
} |
4740 |
} |
| 4741 |
|
4741 |
|
| 4742 |
void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) { |
4742 |
void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) { |
| 4743 |
Check(MD->getNumOperands() >= 2, |
4743 |
Check(MD->getNumOperands() >= 2, |
| 4744 |
"!prof annotations should have no less than 2 operands", MD); |
4744 |
"!prof annotations should have no less than 2 operands", MD); |
| 4745 |
|
4745 |
|
| 4746 |
// Check first operand. |
4746 |
// Check first operand. |
| 4747 |
Check(MD->getOperand(0) != nullptr, "first operand should not be null", MD); |
4747 |
Check(MD->getOperand(0) != nullptr, "first operand should not be null", MD); |
| 4748 |
Check(isa(MD->getOperand(0)), |
4748 |
Check(isa(MD->getOperand(0)), |
| 4749 |
"expected string with name of the !prof annotation", MD); |
4749 |
"expected string with name of the !prof annotation", MD); |
| 4750 |
MDString *MDS = cast(MD->getOperand(0)); |
4750 |
MDString *MDS = cast(MD->getOperand(0)); |
| 4751 |
StringRef ProfName = MDS->getString(); |
4751 |
StringRef ProfName = MDS->getString(); |
| 4752 |
|
4752 |
|
| 4753 |
// Check consistency of !prof branch_weights metadata. |
4753 |
// Check consistency of !prof branch_weights metadata. |
| 4754 |
if (ProfName.equals("branch_weights")) { |
4754 |
if (ProfName.equals("branch_weights")) { |
| 4755 |
if (isa(&I)) { |
4755 |
if (isa(&I)) { |
| 4756 |
Check(MD->getNumOperands() == 2 || MD->getNumOperands() == 3, |
4756 |
Check(MD->getNumOperands() == 2 || MD->getNumOperands() == 3, |
| 4757 |
"Wrong number of InvokeInst branch_weights operands", MD); |
4757 |
"Wrong number of InvokeInst branch_weights operands", MD); |
| 4758 |
} else { |
4758 |
} else { |
| 4759 |
unsigned ExpectedNumOperands = 0; |
4759 |
unsigned ExpectedNumOperands = 0; |
| 4760 |
if (BranchInst *BI = dyn_cast(&I)) |
4760 |
if (BranchInst *BI = dyn_cast(&I)) |
| 4761 |
ExpectedNumOperands = BI->getNumSuccessors(); |
4761 |
ExpectedNumOperands = BI->getNumSuccessors(); |
| 4762 |
else if (SwitchInst *SI = dyn_cast(&I)) |
4762 |
else if (SwitchInst *SI = dyn_cast(&I)) |
| 4763 |
ExpectedNumOperands = SI->getNumSuccessors(); |
4763 |
ExpectedNumOperands = SI->getNumSuccessors(); |
| 4764 |
else if (isa(&I)) |
4764 |
else if (isa(&I)) |
| 4765 |
ExpectedNumOperands = 1; |
4765 |
ExpectedNumOperands = 1; |
| 4766 |
else if (IndirectBrInst *IBI = dyn_cast(&I)) |
4766 |
else if (IndirectBrInst *IBI = dyn_cast(&I)) |
| 4767 |
ExpectedNumOperands = IBI->getNumDestinations(); |
4767 |
ExpectedNumOperands = IBI->getNumDestinations(); |
| 4768 |
else if (isa(&I)) |
4768 |
else if (isa(&I)) |
| 4769 |
ExpectedNumOperands = 2; |
4769 |
ExpectedNumOperands = 2; |
| 4770 |
else if (CallBrInst *CI = dyn_cast(&I)) |
4770 |
else if (CallBrInst *CI = dyn_cast(&I)) |
| 4771 |
ExpectedNumOperands = CI->getNumSuccessors(); |
4771 |
ExpectedNumOperands = CI->getNumSuccessors(); |
| 4772 |
else |
4772 |
else |
| 4773 |
CheckFailed("!prof branch_weights are not allowed for this instruction", |
4773 |
CheckFailed("!prof branch_weights are not allowed for this instruction", |
| 4774 |
MD); |
4774 |
MD); |
| 4775 |
|
4775 |
|
| 4776 |
Check(MD->getNumOperands() == 1 + ExpectedNumOperands, |
4776 |
Check(MD->getNumOperands() == 1 + ExpectedNumOperands, |
| 4777 |
"Wrong number of operands", MD); |
4777 |
"Wrong number of operands", MD); |
| 4778 |
} |
4778 |
} |
| 4779 |
for (unsigned i = 1; i < MD->getNumOperands(); ++i) { |
4779 |
for (unsigned i = 1; i < MD->getNumOperands(); ++i) { |
| 4780 |
auto &MDO = MD->getOperand(i); |
4780 |
auto &MDO = MD->getOperand(i); |
| 4781 |
Check(MDO, "second operand should not be null", MD); |
4781 |
Check(MDO, "second operand should not be null", MD); |
| 4782 |
Check(mdconst::dyn_extract(MDO), |
4782 |
Check(mdconst::dyn_extract(MDO), |
| 4783 |
"!prof brunch_weights operand is not a const int"); |
4783 |
"!prof brunch_weights operand is not a const int"); |
| 4784 |
} |
4784 |
} |
| 4785 |
} |
4785 |
} |
| 4786 |
} |
4786 |
} |
| 4787 |
|
4787 |
|
| 4788 |
void Verifier::visitDIAssignIDMetadata(Instruction &I, MDNode *MD) { |
4788 |
void Verifier::visitDIAssignIDMetadata(Instruction &I, MDNode *MD) { |
| 4789 |
assert(I.hasMetadata(LLVMContext::MD_DIAssignID)); |
4789 |
assert(I.hasMetadata(LLVMContext::MD_DIAssignID)); |
| 4790 |
bool ExpectedInstTy = |
4790 |
bool ExpectedInstTy = |
| 4791 |
isa(I) || isa(I) || isa(I); |
4791 |
isa(I) || isa(I) || isa(I); |
| 4792 |
CheckDI(ExpectedInstTy, "!DIAssignID attached to unexpected instruction kind", |
4792 |
CheckDI(ExpectedInstTy, "!DIAssignID attached to unexpected instruction kind", |
| 4793 |
I, MD); |
4793 |
I, MD); |
| 4794 |
// Iterate over the MetadataAsValue uses of the DIAssignID - these should |
4794 |
// Iterate over the MetadataAsValue uses of the DIAssignID - these should |
| 4795 |
// only be found as DbgAssignIntrinsic operands. |
4795 |
// only be found as DbgAssignIntrinsic operands. |
| 4796 |
if (auto *AsValue = MetadataAsValue::getIfExists(Context, MD)) { |
4796 |
if (auto *AsValue = MetadataAsValue::getIfExists(Context, MD)) { |
| 4797 |
for (auto *User : AsValue->users()) { |
4797 |
for (auto *User : AsValue->users()) { |
| 4798 |
CheckDI(isa(User), |
4798 |
CheckDI(isa(User), |
| 4799 |
"!DIAssignID should only be used by llvm.dbg.assign intrinsics", |
4799 |
"!DIAssignID should only be used by llvm.dbg.assign intrinsics", |
| 4800 |
MD, User); |
4800 |
MD, User); |
| 4801 |
// All of the dbg.assign intrinsics should be in the same function as I. |
4801 |
// All of the dbg.assign intrinsics should be in the same function as I. |
| 4802 |
if (auto *DAI = dyn_cast(User)) |
4802 |
if (auto *DAI = dyn_cast(User)) |
| 4803 |
CheckDI(DAI->getFunction() == I.getFunction(), |
4803 |
CheckDI(DAI->getFunction() == I.getFunction(), |
| 4804 |
"dbg.assign not in same function as inst", DAI, &I); |
4804 |
"dbg.assign not in same function as inst", DAI, &I); |
| 4805 |
} |
4805 |
} |
| 4806 |
} |
4806 |
} |
| 4807 |
} |
4807 |
} |
| 4808 |
|
4808 |
|
| 4809 |
void Verifier::visitCallStackMetadata(MDNode *MD) { |
4809 |
void Verifier::visitCallStackMetadata(MDNode *MD) { |
| 4810 |
// Call stack metadata should consist of a list of at least 1 constant int |
4810 |
// Call stack metadata should consist of a list of at least 1 constant int |
| 4811 |
// (representing a hash of the location). |
4811 |
// (representing a hash of the location). |
| 4812 |
Check(MD->getNumOperands() >= 1, |
4812 |
Check(MD->getNumOperands() >= 1, |
| 4813 |
"call stack metadata should have at least 1 operand", MD); |
4813 |
"call stack metadata should have at least 1 operand", MD); |
| 4814 |
|
4814 |
|
| 4815 |
for (const auto &Op : MD->operands()) |
4815 |
for (const auto &Op : MD->operands()) |
| 4816 |
Check(mdconst::dyn_extract_or_null(Op), |
4816 |
Check(mdconst::dyn_extract_or_null(Op), |
| 4817 |
"call stack metadata operand should be constant integer", Op); |
4817 |
"call stack metadata operand should be constant integer", Op); |
| 4818 |
} |
4818 |
} |
| 4819 |
|
4819 |
|
| 4820 |
void Verifier::visitMemProfMetadata(Instruction &I, MDNode *MD) { |
4820 |
void Verifier::visitMemProfMetadata(Instruction &I, MDNode *MD) { |
| 4821 |
Check(isa(I), "!memprof metadata should only exist on calls", &I); |
4821 |
Check(isa(I), "!memprof metadata should only exist on calls", &I); |
| 4822 |
Check(MD->getNumOperands() >= 1, |
4822 |
Check(MD->getNumOperands() >= 1, |
| 4823 |
"!memprof annotations should have at least 1 metadata operand " |
4823 |
"!memprof annotations should have at least 1 metadata operand " |
| 4824 |
"(MemInfoBlock)", |
4824 |
"(MemInfoBlock)", |
| 4825 |
MD); |
4825 |
MD); |
| 4826 |
|
4826 |
|
| 4827 |
// Check each MIB |
4827 |
// Check each MIB |
| 4828 |
for (auto &MIBOp : MD->operands()) { |
4828 |
for (auto &MIBOp : MD->operands()) { |
| 4829 |
MDNode *MIB = dyn_cast(MIBOp); |
4829 |
MDNode *MIB = dyn_cast(MIBOp); |
| 4830 |
// The first operand of an MIB should be the call stack metadata. |
4830 |
// The first operand of an MIB should be the call stack metadata. |
| 4831 |
// There rest of the operands should be MDString tags, and there should be |
4831 |
// There rest of the operands should be MDString tags, and there should be |
| 4832 |
// at least one. |
4832 |
// at least one. |
| 4833 |
Check(MIB->getNumOperands() >= 2, |
4833 |
Check(MIB->getNumOperands() >= 2, |
| 4834 |
"Each !memprof MemInfoBlock should have at least 2 operands", MIB); |
4834 |
"Each !memprof MemInfoBlock should have at least 2 operands", MIB); |
| 4835 |
|
4835 |
|
| 4836 |
// Check call stack metadata (first operand). |
4836 |
// Check call stack metadata (first operand). |
| 4837 |
Check(MIB->getOperand(0) != nullptr, |
4837 |
Check(MIB->getOperand(0) != nullptr, |
| 4838 |
"!memprof MemInfoBlock first operand should not be null", MIB); |
4838 |
"!memprof MemInfoBlock first operand should not be null", MIB); |
| 4839 |
Check(isa(MIB->getOperand(0)), |
4839 |
Check(isa(MIB->getOperand(0)), |
| 4840 |
"!memprof MemInfoBlock first operand should be an MDNode", MIB); |
4840 |
"!memprof MemInfoBlock first operand should be an MDNode", MIB); |
| 4841 |
MDNode *StackMD = dyn_cast(MIB->getOperand(0)); |
4841 |
MDNode *StackMD = dyn_cast(MIB->getOperand(0)); |
| 4842 |
visitCallStackMetadata(StackMD); |
4842 |
visitCallStackMetadata(StackMD); |
| 4843 |
|
4843 |
|
| 4844 |
// Check that remaining operands are MDString. |
4844 |
// Check that remaining operands are MDString. |
| 4845 |
Check(llvm::all_of(llvm::drop_begin(MIB->operands()), |
4845 |
Check(llvm::all_of(llvm::drop_begin(MIB->operands()), |
| 4846 |
[](const MDOperand &Op) { return isa(Op); }), |
4846 |
[](const MDOperand &Op) { return isa(Op); }), |
| 4847 |
"Not all !memprof MemInfoBlock operands 1 to N are MDString", MIB); |
4847 |
"Not all !memprof MemInfoBlock operands 1 to N are MDString", MIB); |
| 4848 |
} |
4848 |
} |
| 4849 |
} |
4849 |
} |
| 4850 |
|
4850 |
|
| 4851 |
void Verifier::visitCallsiteMetadata(Instruction &I, MDNode *MD) { |
4851 |
void Verifier::visitCallsiteMetadata(Instruction &I, MDNode *MD) { |
| 4852 |
Check(isa(I), "!callsite metadata should only exist on calls", &I); |
4852 |
Check(isa(I), "!callsite metadata should only exist on calls", &I); |
| 4853 |
// Verify the partial callstack annotated from memprof profiles. This callsite |
4853 |
// Verify the partial callstack annotated from memprof profiles. This callsite |
| 4854 |
// is a part of a profiled allocation callstack. |
4854 |
// is a part of a profiled allocation callstack. |
| 4855 |
visitCallStackMetadata(MD); |
4855 |
visitCallStackMetadata(MD); |
| 4856 |
} |
4856 |
} |
| 4857 |
|
4857 |
|
| 4858 |
void Verifier::visitAnnotationMetadata(MDNode *Annotation) { |
4858 |
void Verifier::visitAnnotationMetadata(MDNode *Annotation) { |
| 4859 |
Check(isa(Annotation), "annotation must be a tuple"); |
4859 |
Check(isa(Annotation), "annotation must be a tuple"); |
| 4860 |
Check(Annotation->getNumOperands() >= 1, |
4860 |
Check(Annotation->getNumOperands() >= 1, |
| 4861 |
"annotation must have at least one operand"); |
4861 |
"annotation must have at least one operand"); |
| 4862 |
for (const MDOperand &Op : Annotation->operands()) { |
4862 |
for (const MDOperand &Op : Annotation->operands()) { |
| 4863 |
bool TupleOfStrings = |
4863 |
bool TupleOfStrings = |
| 4864 |
isa(Op.get()) && |
4864 |
isa(Op.get()) && |
| 4865 |
all_of(cast(Op)->operands(), [](auto &Annotation) { |
4865 |
all_of(cast(Op)->operands(), [](auto &Annotation) { |
| 4866 |
return isa(Annotation.get()); |
4866 |
return isa(Annotation.get()); |
| 4867 |
}); |
4867 |
}); |
| 4868 |
Check(isa(Op.get()) || TupleOfStrings, |
4868 |
Check(isa(Op.get()) || TupleOfStrings, |
| 4869 |
"operands must be a string or a tuple of strings"); |
4869 |
"operands must be a string or a tuple of strings"); |
| 4870 |
} |
4870 |
} |
| 4871 |
} |
4871 |
} |
| 4872 |
|
4872 |
|
| 4873 |
void Verifier::visitAliasScopeMetadata(const MDNode *MD) { |
4873 |
void Verifier::visitAliasScopeMetadata(const MDNode *MD) { |
| 4874 |
unsigned NumOps = MD->getNumOperands(); |
4874 |
unsigned NumOps = MD->getNumOperands(); |
| 4875 |
Check(NumOps >= 2 && NumOps <= 3, "scope must have two or three operands", |
4875 |
Check(NumOps >= 2 && NumOps <= 3, "scope must have two or three operands", |
| 4876 |
MD); |
4876 |
MD); |
| 4877 |
Check(MD->getOperand(0).get() == MD || isa(MD->getOperand(0)), |
4877 |
Check(MD->getOperand(0).get() == MD || isa(MD->getOperand(0)), |
| 4878 |
"first scope operand must be self-referential or string", MD); |
4878 |
"first scope operand must be self-referential or string", MD); |
| 4879 |
if (NumOps == 3) |
4879 |
if (NumOps == 3) |
| 4880 |
Check(isa(MD->getOperand(2)), |
4880 |
Check(isa(MD->getOperand(2)), |
| 4881 |
"third scope operand must be string (if used)", MD); |
4881 |
"third scope operand must be string (if used)", MD); |
| 4882 |
|
4882 |
|
| 4883 |
MDNode *Domain = dyn_cast(MD->getOperand(1)); |
4883 |
MDNode *Domain = dyn_cast(MD->getOperand(1)); |
| 4884 |
Check(Domain != nullptr, "second scope operand must be MDNode", MD); |
4884 |
Check(Domain != nullptr, "second scope operand must be MDNode", MD); |
| 4885 |
|
4885 |
|
| 4886 |
unsigned NumDomainOps = Domain->getNumOperands(); |
4886 |
unsigned NumDomainOps = Domain->getNumOperands(); |
| 4887 |
Check(NumDomainOps >= 1 && NumDomainOps <= 2, |
4887 |
Check(NumDomainOps >= 1 && NumDomainOps <= 2, |
| 4888 |
"domain must have one or two operands", Domain); |
4888 |
"domain must have one or two operands", Domain); |
| 4889 |
Check(Domain->getOperand(0).get() == Domain || |
4889 |
Check(Domain->getOperand(0).get() == Domain || |
| 4890 |
isa(Domain->getOperand(0)), |
4890 |
isa(Domain->getOperand(0)), |
| 4891 |
"first domain operand must be self-referential or string", Domain); |
4891 |
"first domain operand must be self-referential or string", Domain); |
| 4892 |
if (NumDomainOps == 2) |
4892 |
if (NumDomainOps == 2) |
| 4893 |
Check(isa(Domain->getOperand(1)), |
4893 |
Check(isa(Domain->getOperand(1)), |
| 4894 |
"second domain operand must be string (if used)", Domain); |
4894 |
"second domain operand must be string (if used)", Domain); |
| 4895 |
} |
4895 |
} |
| 4896 |
|
4896 |
|
| 4897 |
void Verifier::visitAliasScopeListMetadata(const MDNode *MD) { |
4897 |
void Verifier::visitAliasScopeListMetadata(const MDNode *MD) { |
| 4898 |
for (const MDOperand &Op : MD->operands()) { |
4898 |
for (const MDOperand &Op : MD->operands()) { |
| 4899 |
const MDNode *OpMD = dyn_cast(Op); |
4899 |
const MDNode *OpMD = dyn_cast(Op); |
| 4900 |
Check(OpMD != nullptr, "scope list must consist of MDNodes", MD); |
4900 |
Check(OpMD != nullptr, "scope list must consist of MDNodes", MD); |
| 4901 |
visitAliasScopeMetadata(OpMD); |
4901 |
visitAliasScopeMetadata(OpMD); |
| 4902 |
} |
4902 |
} |
| 4903 |
} |
4903 |
} |
| 4904 |
|
4904 |
|
| 4905 |
void Verifier::visitAccessGroupMetadata(const MDNode *MD) { |
4905 |
void Verifier::visitAccessGroupMetadata(const MDNode *MD) { |
| 4906 |
auto IsValidAccessScope = [](const MDNode *MD) { |
4906 |
auto IsValidAccessScope = [](const MDNode *MD) { |
| 4907 |
return MD->getNumOperands() == 0 && MD->isDistinct(); |
4907 |
return MD->getNumOperands() == 0 && MD->isDistinct(); |
| 4908 |
}; |
4908 |
}; |
| 4909 |
|
4909 |
|
| 4910 |
// It must be either an access scope itself... |
4910 |
// It must be either an access scope itself... |
| 4911 |
if (IsValidAccessScope(MD)) |
4911 |
if (IsValidAccessScope(MD)) |
| 4912 |
return; |
4912 |
return; |
| 4913 |
|
4913 |
|
| 4914 |
// ...or a list of access scopes. |
4914 |
// ...or a list of access scopes. |
| 4915 |
for (const MDOperand &Op : MD->operands()) { |
4915 |
for (const MDOperand &Op : MD->operands()) { |
| 4916 |
const MDNode *OpMD = dyn_cast(Op); |
4916 |
const MDNode *OpMD = dyn_cast(Op); |
| 4917 |
Check(OpMD != nullptr, "Access scope list must consist of MDNodes", MD); |
4917 |
Check(OpMD != nullptr, "Access scope list must consist of MDNodes", MD); |
| 4918 |
Check(IsValidAccessScope(OpMD), |
4918 |
Check(IsValidAccessScope(OpMD), |
| 4919 |
"Access scope list contains invalid access scope", MD); |
4919 |
"Access scope list contains invalid access scope", MD); |
| 4920 |
} |
4920 |
} |
| 4921 |
} |
4921 |
} |
| 4922 |
|
4922 |
|
| 4923 |
/// verifyInstruction - Verify that an instruction is well formed. |
4923 |
/// verifyInstruction - Verify that an instruction is well formed. |
| 4924 |
/// |
4924 |
/// |
| 4925 |
void Verifier::visitInstruction(Instruction &I) { |
4925 |
void Verifier::visitInstruction(Instruction &I) { |
| 4926 |
BasicBlock *BB = I.getParent(); |
4926 |
BasicBlock *BB = I.getParent(); |
| 4927 |
Check(BB, "Instruction not embedded in basic block!", &I); |
4927 |
Check(BB, "Instruction not embedded in basic block!", &I); |
| 4928 |
|
4928 |
|
| 4929 |
if (!isa(I)) { // Check that non-phi nodes are not self referential |
4929 |
if (!isa(I)) { // Check that non-phi nodes are not self referential |
| 4930 |
for (User *U : I.users()) { |
4930 |
for (User *U : I.users()) { |
| 4931 |
Check(U != (User *)&I || !DT.isReachableFromEntry(BB), |
4931 |
Check(U != (User *)&I || !DT.isReachableFromEntry(BB), |
| 4932 |
"Only PHI nodes may reference their own value!", &I); |
4932 |
"Only PHI nodes may reference their own value!", &I); |
| 4933 |
} |
4933 |
} |
| 4934 |
} |
4934 |
} |
| 4935 |
|
4935 |
|
| 4936 |
// Check that void typed values don't have names |
4936 |
// Check that void typed values don't have names |
| 4937 |
Check(!I.getType()->isVoidTy() || !I.hasName(), |
4937 |
Check(!I.getType()->isVoidTy() || !I.hasName(), |
| 4938 |
"Instruction has a name, but provides a void value!", &I); |
4938 |
"Instruction has a name, but provides a void value!", &I); |
| 4939 |
|
4939 |
|
| 4940 |
// Check that the return value of the instruction is either void or a legal |
4940 |
// Check that the return value of the instruction is either void or a legal |
| 4941 |
// value type. |
4941 |
// value type. |
| 4942 |
Check(I.getType()->isVoidTy() || I.getType()->isFirstClassType(), |
4942 |
Check(I.getType()->isVoidTy() || I.getType()->isFirstClassType(), |
| 4943 |
"Instruction returns a non-scalar type!", &I); |
4943 |
"Instruction returns a non-scalar type!", &I); |
| 4944 |
|
4944 |
|
| 4945 |
// Check that the instruction doesn't produce metadata. Calls are already |
4945 |
// Check that the instruction doesn't produce metadata. Calls are already |
| 4946 |
// checked against the callee type. |
4946 |
// checked against the callee type. |
| 4947 |
Check(!I.getType()->isMetadataTy() || isa(I) || isa(I), |
4947 |
Check(!I.getType()->isMetadataTy() || isa(I) || isa(I), |
| 4948 |
"Invalid use of metadata!", &I); |
4948 |
"Invalid use of metadata!", &I); |
| 4949 |
|
4949 |
|
| 4950 |
// Check that all uses of the instruction, if they are instructions |
4950 |
// Check that all uses of the instruction, if they are instructions |
| 4951 |
// themselves, actually have parent basic blocks. If the use is not an |
4951 |
// themselves, actually have parent basic blocks. If the use is not an |
| 4952 |
// instruction, it is an error! |
4952 |
// instruction, it is an error! |
| 4953 |
for (Use &U : I.uses()) { |
4953 |
for (Use &U : I.uses()) { |
| 4954 |
if (Instruction *Used = dyn_cast(U.getUser())) |
4954 |
if (Instruction *Used = dyn_cast(U.getUser())) |
| 4955 |
Check(Used->getParent() != nullptr, |
4955 |
Check(Used->getParent() != nullptr, |
| 4956 |
"Instruction referencing" |
4956 |
"Instruction referencing" |
| 4957 |
" instruction not embedded in a basic block!", |
4957 |
" instruction not embedded in a basic block!", |
| 4958 |
&I, Used); |
4958 |
&I, Used); |
| 4959 |
else { |
4959 |
else { |
| 4960 |
CheckFailed("Use of instruction is not an instruction!", U); |
4960 |
CheckFailed("Use of instruction is not an instruction!", U); |
| 4961 |
return; |
4961 |
return; |
| 4962 |
} |
4962 |
} |
| 4963 |
} |
4963 |
} |
| 4964 |
|
4964 |
|
| 4965 |
// Get a pointer to the call base of the instruction if it is some form of |
4965 |
// Get a pointer to the call base of the instruction if it is some form of |
| 4966 |
// call. |
4966 |
// call. |
| 4967 |
const CallBase *CBI = dyn_cast(&I); |
4967 |
const CallBase *CBI = dyn_cast(&I); |
| 4968 |
|
4968 |
|
| 4969 |
for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) { |
4969 |
for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) { |
| 4970 |
Check(I.getOperand(i) != nullptr, "Instruction has null operand!", &I); |
4970 |
Check(I.getOperand(i) != nullptr, "Instruction has null operand!", &I); |
| 4971 |
|
4971 |
|
| 4972 |
// Check to make sure that only first-class-values are operands to |
4972 |
// Check to make sure that only first-class-values are operands to |
| 4973 |
// instructions. |
4973 |
// instructions. |
| 4974 |
if (!I.getOperand(i)->getType()->isFirstClassType()) { |
4974 |
if (!I.getOperand(i)->getType()->isFirstClassType()) { |
| 4975 |
Check(false, "Instruction operands must be first-class values!", &I); |
4975 |
Check(false, "Instruction operands must be first-class values!", &I); |
| 4976 |
} |
4976 |
} |
| 4977 |
|
4977 |
|
| 4978 |
if (Function *F = dyn_cast(I.getOperand(i))) { |
4978 |
if (Function *F = dyn_cast(I.getOperand(i))) { |
| 4979 |
// This code checks whether the function is used as the operand of a |
4979 |
// This code checks whether the function is used as the operand of a |
| 4980 |
// clang_arc_attachedcall operand bundle. |
4980 |
// clang_arc_attachedcall operand bundle. |
| 4981 |
auto IsAttachedCallOperand = [](Function *F, const CallBase *CBI, |
4981 |
auto IsAttachedCallOperand = [](Function *F, const CallBase *CBI, |
| 4982 |
int Idx) { |
4982 |
int Idx) { |
| 4983 |
return CBI && CBI->isOperandBundleOfType( |
4983 |
return CBI && CBI->isOperandBundleOfType( |
| 4984 |
LLVMContext::OB_clang_arc_attachedcall, Idx); |
4984 |
LLVMContext::OB_clang_arc_attachedcall, Idx); |
| 4985 |
}; |
4985 |
}; |
| 4986 |
|
4986 |
|
| 4987 |
// Check to make sure that the "address of" an intrinsic function is never |
4987 |
// Check to make sure that the "address of" an intrinsic function is never |
| 4988 |
// taken. Ignore cases where the address of the intrinsic function is used |
4988 |
// taken. Ignore cases where the address of the intrinsic function is used |
| 4989 |
// as the argument of operand bundle "clang.arc.attachedcall" as those |
4989 |
// as the argument of operand bundle "clang.arc.attachedcall" as those |
| 4990 |
// cases are handled in verifyAttachedCallBundle. |
4990 |
// cases are handled in verifyAttachedCallBundle. |
| 4991 |
Check((!F->isIntrinsic() || |
4991 |
Check((!F->isIntrinsic() || |
| 4992 |
(CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i)) || |
4992 |
(CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i)) || |
| 4993 |
IsAttachedCallOperand(F, CBI, i)), |
4993 |
IsAttachedCallOperand(F, CBI, i)), |
| 4994 |
"Cannot take the address of an intrinsic!", &I); |
4994 |
"Cannot take the address of an intrinsic!", &I); |
| 4995 |
Check(!F->isIntrinsic() || isa(I) || |
4995 |
Check(!F->isIntrinsic() || isa(I) || |
| 4996 |
F->getIntrinsicID() == Intrinsic::donothing || |
4996 |
F->getIntrinsicID() == Intrinsic::donothing || |
| 4997 |
F->getIntrinsicID() == Intrinsic::seh_try_begin || |
4997 |
F->getIntrinsicID() == Intrinsic::seh_try_begin || |
| 4998 |
F->getIntrinsicID() == Intrinsic::seh_try_end || |
4998 |
F->getIntrinsicID() == Intrinsic::seh_try_end || |
| 4999 |
F->getIntrinsicID() == Intrinsic::seh_scope_begin || |
4999 |
F->getIntrinsicID() == Intrinsic::seh_scope_begin || |
| 5000 |
F->getIntrinsicID() == Intrinsic::seh_scope_end || |
5000 |
F->getIntrinsicID() == Intrinsic::seh_scope_end || |
| 5001 |
F->getIntrinsicID() == Intrinsic::coro_resume || |
5001 |
F->getIntrinsicID() == Intrinsic::coro_resume || |
| 5002 |
F->getIntrinsicID() == Intrinsic::coro_destroy || |
5002 |
F->getIntrinsicID() == Intrinsic::coro_destroy || |
| 5003 |
F->getIntrinsicID() == |
5003 |
F->getIntrinsicID() == |
| 5004 |
Intrinsic::experimental_patchpoint_void || |
5004 |
Intrinsic::experimental_patchpoint_void || |
| 5005 |
F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || |
5005 |
F->getIntrinsicID() == Intrinsic::experimental_patchpoint_i64 || |
| 5006 |
F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || |
5006 |
F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint || |
| 5007 |
F->getIntrinsicID() == Intrinsic::wasm_rethrow || |
5007 |
F->getIntrinsicID() == Intrinsic::wasm_rethrow || |
| 5008 |
IsAttachedCallOperand(F, CBI, i), |
5008 |
IsAttachedCallOperand(F, CBI, i), |
| 5009 |
"Cannot invoke an intrinsic other than donothing, patchpoint, " |
5009 |
"Cannot invoke an intrinsic other than donothing, patchpoint, " |
| 5010 |
"statepoint, coro_resume, coro_destroy or clang.arc.attachedcall", |
5010 |
"statepoint, coro_resume, coro_destroy or clang.arc.attachedcall", |
| 5011 |
&I); |
5011 |
&I); |
| 5012 |
Check(F->getParent() == &M, "Referencing function in another module!", &I, |
5012 |
Check(F->getParent() == &M, "Referencing function in another module!", &I, |
| 5013 |
&M, F, F->getParent()); |
5013 |
&M, F, F->getParent()); |
| 5014 |
} else if (BasicBlock *OpBB = dyn_cast(I.getOperand(i))) { |
5014 |
} else if (BasicBlock *OpBB = dyn_cast(I.getOperand(i))) { |
| 5015 |
Check(OpBB->getParent() == BB->getParent(), |
5015 |
Check(OpBB->getParent() == BB->getParent(), |
| 5016 |
"Referring to a basic block in another function!", &I); |
5016 |
"Referring to a basic block in another function!", &I); |
| 5017 |
} else if (Argument *OpArg = dyn_cast(I.getOperand(i))) { |
5017 |
} else if (Argument *OpArg = dyn_cast(I.getOperand(i))) { |
| 5018 |
Check(OpArg->getParent() == BB->getParent(), |
5018 |
Check(OpArg->getParent() == BB->getParent(), |
| 5019 |
"Referring to an argument in another function!", &I); |
5019 |
"Referring to an argument in another function!", &I); |
| 5020 |
} else if (GlobalValue *GV = dyn_cast(I.getOperand(i))) { |
5020 |
} else if (GlobalValue *GV = dyn_cast(I.getOperand(i))) { |
| 5021 |
Check(GV->getParent() == &M, "Referencing global in another module!", &I, |
5021 |
Check(GV->getParent() == &M, "Referencing global in another module!", &I, |
| 5022 |
&M, GV, GV->getParent()); |
5022 |
&M, GV, GV->getParent()); |
| 5023 |
} else if (isa(I.getOperand(i))) { |
5023 |
} else if (isa(I.getOperand(i))) { |
| 5024 |
verifyDominatesUse(I, i); |
5024 |
verifyDominatesUse(I, i); |
| 5025 |
} else if (isa(I.getOperand(i))) { |
5025 |
} else if (isa(I.getOperand(i))) { |
| 5026 |
Check(CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i), |
5026 |
Check(CBI && &CBI->getCalledOperandUse() == &I.getOperandUse(i), |
| 5027 |
"Cannot take the address of an inline asm!", &I); |
5027 |
"Cannot take the address of an inline asm!", &I); |
| 5028 |
} else if (ConstantExpr *CE = dyn_cast(I.getOperand(i))) { |
5028 |
} else if (ConstantExpr *CE = dyn_cast(I.getOperand(i))) { |
| 5029 |
if (CE->getType()->isPtrOrPtrVectorTy()) { |
5029 |
if (CE->getType()->isPtrOrPtrVectorTy()) { |
| 5030 |
// If we have a ConstantExpr pointer, we need to see if it came from an |
5030 |
// If we have a ConstantExpr pointer, we need to see if it came from an |
| 5031 |
// illegal bitcast. |
5031 |
// illegal bitcast. |
| 5032 |
visitConstantExprsRecursively(CE); |
5032 |
visitConstantExprsRecursively(CE); |
| 5033 |
} |
5033 |
} |
| 5034 |
} |
5034 |
} |
| 5035 |
} |
5035 |
} |
| 5036 |
|
5036 |
|
| 5037 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) { |
5037 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_fpmath)) { |
| 5038 |
Check(I.getType()->isFPOrFPVectorTy(), |
5038 |
Check(I.getType()->isFPOrFPVectorTy(), |
| 5039 |
"fpmath requires a floating point result!", &I); |
5039 |
"fpmath requires a floating point result!", &I); |
| 5040 |
Check(MD->getNumOperands() == 1, "fpmath takes one operand!", &I); |
5040 |
Check(MD->getNumOperands() == 1, "fpmath takes one operand!", &I); |
| 5041 |
if (ConstantFP *CFP0 = |
5041 |
if (ConstantFP *CFP0 = |
| 5042 |
mdconst::dyn_extract_or_null(MD->getOperand(0))) { |
5042 |
mdconst::dyn_extract_or_null(MD->getOperand(0))) { |
| 5043 |
const APFloat &Accuracy = CFP0->getValueAPF(); |
5043 |
const APFloat &Accuracy = CFP0->getValueAPF(); |
| 5044 |
Check(&Accuracy.getSemantics() == &APFloat::IEEEsingle(), |
5044 |
Check(&Accuracy.getSemantics() == &APFloat::IEEEsingle(), |
| 5045 |
"fpmath accuracy must have float type", &I); |
5045 |
"fpmath accuracy must have float type", &I); |
| 5046 |
Check(Accuracy.isFiniteNonZero() && !Accuracy.isNegative(), |
5046 |
Check(Accuracy.isFiniteNonZero() && !Accuracy.isNegative(), |
| 5047 |
"fpmath accuracy not a positive number!", &I); |
5047 |
"fpmath accuracy not a positive number!", &I); |
| 5048 |
} else { |
5048 |
} else { |
| 5049 |
Check(false, "invalid fpmath accuracy!", &I); |
5049 |
Check(false, "invalid fpmath accuracy!", &I); |
| 5050 |
} |
5050 |
} |
| 5051 |
} |
5051 |
} |
| 5052 |
|
5052 |
|
| 5053 |
if (MDNode *Range = I.getMetadata(LLVMContext::MD_range)) { |
5053 |
if (MDNode *Range = I.getMetadata(LLVMContext::MD_range)) { |
| 5054 |
Check(isa(I) || isa(I) || isa(I), |
5054 |
Check(isa(I) || isa(I) || isa(I), |
| 5055 |
"Ranges are only for loads, calls and invokes!", &I); |
5055 |
"Ranges are only for loads, calls and invokes!", &I); |
| 5056 |
visitRangeMetadata(I, Range, I.getType()); |
5056 |
visitRangeMetadata(I, Range, I.getType()); |
| 5057 |
} |
5057 |
} |
| 5058 |
|
5058 |
|
| 5059 |
if (I.hasMetadata(LLVMContext::MD_invariant_group)) { |
5059 |
if (I.hasMetadata(LLVMContext::MD_invariant_group)) { |
| 5060 |
Check(isa(I) || isa(I), |
5060 |
Check(isa(I) || isa(I), |
| 5061 |
"invariant.group metadata is only for loads and stores", &I); |
5061 |
"invariant.group metadata is only for loads and stores", &I); |
| 5062 |
} |
5062 |
} |
| 5063 |
|
5063 |
|
| 5064 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_nonnull)) { |
5064 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_nonnull)) { |
| 5065 |
Check(I.getType()->isPointerTy(), "nonnull applies only to pointer types", |
5065 |
Check(I.getType()->isPointerTy(), "nonnull applies only to pointer types", |
| 5066 |
&I); |
5066 |
&I); |
| 5067 |
Check(isa(I), |
5067 |
Check(isa(I), |
| 5068 |
"nonnull applies only to load instructions, use attributes" |
5068 |
"nonnull applies only to load instructions, use attributes" |
| 5069 |
" for calls or invokes", |
5069 |
" for calls or invokes", |
| 5070 |
&I); |
5070 |
&I); |
| 5071 |
Check(MD->getNumOperands() == 0, "nonnull metadata must be empty", &I); |
5071 |
Check(MD->getNumOperands() == 0, "nonnull metadata must be empty", &I); |
| 5072 |
} |
5072 |
} |
| 5073 |
|
5073 |
|
| 5074 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable)) |
5074 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable)) |
| 5075 |
visitDereferenceableMetadata(I, MD); |
5075 |
visitDereferenceableMetadata(I, MD); |
| 5076 |
|
5076 |
|
| 5077 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable_or_null)) |
5077 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable_or_null)) |
| 5078 |
visitDereferenceableMetadata(I, MD); |
5078 |
visitDereferenceableMetadata(I, MD); |
| 5079 |
|
5079 |
|
| 5080 |
if (MDNode *TBAA = I.getMetadata(LLVMContext::MD_tbaa)) |
5080 |
if (MDNode *TBAA = I.getMetadata(LLVMContext::MD_tbaa)) |
| 5081 |
TBAAVerifyHelper.visitTBAAMetadata(I, TBAA); |
5081 |
TBAAVerifyHelper.visitTBAAMetadata(I, TBAA); |
| 5082 |
|
5082 |
|
| 5083 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_noalias)) |
5083 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_noalias)) |
| 5084 |
visitAliasScopeListMetadata(MD); |
5084 |
visitAliasScopeListMetadata(MD); |
| 5085 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_alias_scope)) |
5085 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_alias_scope)) |
| 5086 |
visitAliasScopeListMetadata(MD); |
5086 |
visitAliasScopeListMetadata(MD); |
| 5087 |
|
5087 |
|
| 5088 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_access_group)) |
5088 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_access_group)) |
| 5089 |
visitAccessGroupMetadata(MD); |
5089 |
visitAccessGroupMetadata(MD); |
| 5090 |
|
5090 |
|
| 5091 |
if (MDNode *AlignMD = I.getMetadata(LLVMContext::MD_align)) { |
5091 |
if (MDNode *AlignMD = I.getMetadata(LLVMContext::MD_align)) { |
| 5092 |
Check(I.getType()->isPointerTy(), "align applies only to pointer types", |
5092 |
Check(I.getType()->isPointerTy(), "align applies only to pointer types", |
| 5093 |
&I); |
5093 |
&I); |
| 5094 |
Check(isa(I), |
5094 |
Check(isa(I), |
| 5095 |
"align applies only to load instructions, " |
5095 |
"align applies only to load instructions, " |
| 5096 |
"use attributes for calls or invokes", |
5096 |
"use attributes for calls or invokes", |
| 5097 |
&I); |
5097 |
&I); |
| 5098 |
Check(AlignMD->getNumOperands() == 1, "align takes one operand!", &I); |
5098 |
Check(AlignMD->getNumOperands() == 1, "align takes one operand!", &I); |
| 5099 |
ConstantInt *CI = mdconst::dyn_extract(AlignMD->getOperand(0)); |
5099 |
ConstantInt *CI = mdconst::dyn_extract(AlignMD->getOperand(0)); |
| 5100 |
Check(CI && CI->getType()->isIntegerTy(64), |
5100 |
Check(CI && CI->getType()->isIntegerTy(64), |
| 5101 |
"align metadata value must be an i64!", &I); |
5101 |
"align metadata value must be an i64!", &I); |
| 5102 |
uint64_t Align = CI->getZExtValue(); |
5102 |
uint64_t Align = CI->getZExtValue(); |
| 5103 |
Check(isPowerOf2_64(Align), "align metadata value must be a power of 2!", |
5103 |
Check(isPowerOf2_64(Align), "align metadata value must be a power of 2!", |
| 5104 |
&I); |
5104 |
&I); |
| 5105 |
Check(Align <= Value::MaximumAlignment, |
5105 |
Check(Align <= Value::MaximumAlignment, |
| 5106 |
"alignment is larger that implementation defined limit", &I); |
5106 |
"alignment is larger that implementation defined limit", &I); |
| 5107 |
} |
5107 |
} |
| 5108 |
|
5108 |
|
| 5109 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_prof)) |
5109 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_prof)) |
| 5110 |
visitProfMetadata(I, MD); |
5110 |
visitProfMetadata(I, MD); |
| 5111 |
|
5111 |
|
| 5112 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_memprof)) |
5112 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_memprof)) |
| 5113 |
visitMemProfMetadata(I, MD); |
5113 |
visitMemProfMetadata(I, MD); |
| 5114 |
|
5114 |
|
| 5115 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_callsite)) |
5115 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_callsite)) |
| 5116 |
visitCallsiteMetadata(I, MD); |
5116 |
visitCallsiteMetadata(I, MD); |
| 5117 |
|
5117 |
|
| 5118 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_DIAssignID)) |
5118 |
if (MDNode *MD = I.getMetadata(LLVMContext::MD_DIAssignID)) |
| 5119 |
visitDIAssignIDMetadata(I, MD); |
5119 |
visitDIAssignIDMetadata(I, MD); |
| 5120 |
|
5120 |
|
| 5121 |
if (MDNode *Annotation = I.getMetadata(LLVMContext::MD_annotation)) |
5121 |
if (MDNode *Annotation = I.getMetadata(LLVMContext::MD_annotation)) |
| 5122 |
visitAnnotationMetadata(Annotation); |
5122 |
visitAnnotationMetadata(Annotation); |
| 5123 |
|
5123 |
|
| 5124 |
if (MDNode *N = I.getDebugLoc().getAsMDNode()) { |
5124 |
if (MDNode *N = I.getDebugLoc().getAsMDNode()) { |
| 5125 |
CheckDI(isa(N), "invalid !dbg metadata attachment", &I, N); |
5125 |
CheckDI(isa(N), "invalid !dbg metadata attachment", &I, N); |
| 5126 |
visitMDNode(*N, AreDebugLocsAllowed::Yes); |
5126 |
visitMDNode(*N, AreDebugLocsAllowed::Yes); |
| 5127 |
} |
5127 |
} |
| 5128 |
|
5128 |
|
| 5129 |
if (auto *DII = dyn_cast(&I)) { |
5129 |
if (auto *DII = dyn_cast(&I)) { |
| 5130 |
verifyFragmentExpression(*DII); |
5130 |
verifyFragmentExpression(*DII); |
| 5131 |
verifyNotEntryValue(*DII); |
5131 |
verifyNotEntryValue(*DII); |
| 5132 |
} |
5132 |
} |
| 5133 |
|
5133 |
|
| 5134 |
SmallVector, 4> MDs; |
5134 |
SmallVector, 4> MDs; |
| 5135 |
I.getAllMetadata(MDs); |
5135 |
I.getAllMetadata(MDs); |
| 5136 |
for (auto Attachment : MDs) { |
5136 |
for (auto Attachment : MDs) { |
| 5137 |
unsigned Kind = Attachment.first; |
5137 |
unsigned Kind = Attachment.first; |
| 5138 |
auto AllowLocs = |
5138 |
auto AllowLocs = |
| 5139 |
(Kind == LLVMContext::MD_dbg || Kind == LLVMContext::MD_loop) |
5139 |
(Kind == LLVMContext::MD_dbg || Kind == LLVMContext::MD_loop) |
| 5140 |
? AreDebugLocsAllowed::Yes |
5140 |
? AreDebugLocsAllowed::Yes |
| 5141 |
: AreDebugLocsAllowed::No; |
5141 |
: AreDebugLocsAllowed::No; |
| 5142 |
visitMDNode(*Attachment.second, AllowLocs); |
5142 |
visitMDNode(*Attachment.second, AllowLocs); |
| 5143 |
} |
5143 |
} |
| 5144 |
|
5144 |
|
| 5145 |
InstsInThisBlock.insert(&I); |
5145 |
InstsInThisBlock.insert(&I); |
| 5146 |
} |
5146 |
} |
| 5147 |
|
5147 |
|
| 5148 |
/// Allow intrinsics to be verified in different ways. |
5148 |
/// Allow intrinsics to be verified in different ways. |
| 5149 |
void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) { |
5149 |
void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) { |
| 5150 |
Function *IF = Call.getCalledFunction(); |
5150 |
Function *IF = Call.getCalledFunction(); |
| 5151 |
Check(IF->isDeclaration(), "Intrinsic functions should never be defined!", |
5151 |
Check(IF->isDeclaration(), "Intrinsic functions should never be defined!", |
| 5152 |
IF); |
5152 |
IF); |
| 5153 |
|
5153 |
|
| 5154 |
// Verify that the intrinsic prototype lines up with what the .td files |
5154 |
// Verify that the intrinsic prototype lines up with what the .td files |
| 5155 |
// describe. |
5155 |
// describe. |
| 5156 |
FunctionType *IFTy = IF->getFunctionType(); |
5156 |
FunctionType *IFTy = IF->getFunctionType(); |
| 5157 |
bool IsVarArg = IFTy->isVarArg(); |
5157 |
bool IsVarArg = IFTy->isVarArg(); |
| 5158 |
|
5158 |
|
| 5159 |
SmallVector Table; |
5159 |
SmallVector Table; |
| 5160 |
getIntrinsicInfoTableEntries(ID, Table); |
5160 |
getIntrinsicInfoTableEntries(ID, Table); |
| 5161 |
ArrayRef TableRef = Table; |
5161 |
ArrayRef TableRef = Table; |
| 5162 |
|
5162 |
|
| 5163 |
// Walk the descriptors to extract overloaded types. |
5163 |
// Walk the descriptors to extract overloaded types. |
| 5164 |
SmallVector ArgTys; |
5164 |
SmallVector ArgTys; |
| 5165 |
Intrinsic::MatchIntrinsicTypesResult Res = |
5165 |
Intrinsic::MatchIntrinsicTypesResult Res = |
| 5166 |
Intrinsic::matchIntrinsicSignature(IFTy, TableRef, ArgTys); |
5166 |
Intrinsic::matchIntrinsicSignature(IFTy, TableRef, ArgTys); |
| 5167 |
Check(Res != Intrinsic::MatchIntrinsicTypes_NoMatchRet, |
5167 |
Check(Res != Intrinsic::MatchIntrinsicTypes_NoMatchRet, |
| 5168 |
"Intrinsic has incorrect return type!", IF); |
5168 |
"Intrinsic has incorrect return type!", IF); |
| 5169 |
Check(Res != Intrinsic::MatchIntrinsicTypes_NoMatchArg, |
5169 |
Check(Res != Intrinsic::MatchIntrinsicTypes_NoMatchArg, |
| 5170 |
"Intrinsic has incorrect argument type!", IF); |
5170 |
"Intrinsic has incorrect argument type!", IF); |
| 5171 |
|
5171 |
|
| 5172 |
// Verify if the intrinsic call matches the vararg property. |
5172 |
// Verify if the intrinsic call matches the vararg property. |
| 5173 |
if (IsVarArg) |
5173 |
if (IsVarArg) |
| 5174 |
Check(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef), |
5174 |
Check(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef), |
| 5175 |
"Intrinsic was not defined with variable arguments!", IF); |
5175 |
"Intrinsic was not defined with variable arguments!", IF); |
| 5176 |
else |
5176 |
else |
| 5177 |
Check(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef), |
5177 |
Check(!Intrinsic::matchIntrinsicVarArg(IsVarArg, TableRef), |
| 5178 |
"Callsite was not defined with variable arguments!", IF); |
5178 |
"Callsite was not defined with variable arguments!", IF); |
| 5179 |
|
5179 |
|
| 5180 |
// All descriptors should be absorbed by now. |
5180 |
// All descriptors should be absorbed by now. |
| 5181 |
Check(TableRef.empty(), "Intrinsic has too few arguments!", IF); |
5181 |
Check(TableRef.empty(), "Intrinsic has too few arguments!", IF); |
| 5182 |
|
5182 |
|
| 5183 |
// Now that we have the intrinsic ID and the actual argument types (and we |
5183 |
// Now that we have the intrinsic ID and the actual argument types (and we |
| 5184 |
// know they are legal for the intrinsic!) get the intrinsic name through the |
5184 |
// know they are legal for the intrinsic!) get the intrinsic name through the |
| 5185 |
// usual means. This allows us to verify the mangling of argument types into |
5185 |
// usual means. This allows us to verify the mangling of argument types into |
| 5186 |
// the name. |
5186 |
// the name. |
| 5187 |
const std::string ExpectedName = |
5187 |
const std::string ExpectedName = |
| 5188 |
Intrinsic::getName(ID, ArgTys, IF->getParent(), IFTy); |
5188 |
Intrinsic::getName(ID, ArgTys, IF->getParent(), IFTy); |
| 5189 |
Check(ExpectedName == IF->getName(), |
5189 |
Check(ExpectedName == IF->getName(), |
| 5190 |
"Intrinsic name not mangled correctly for type arguments! " |
5190 |
"Intrinsic name not mangled correctly for type arguments! " |
| 5191 |
"Should be: " + |
5191 |
"Should be: " + |
| 5192 |
ExpectedName, |
5192 |
ExpectedName, |
| 5193 |
IF); |
5193 |
IF); |
| 5194 |
|
5194 |
|
| 5195 |
// If the intrinsic takes MDNode arguments, verify that they are either global |
5195 |
// If the intrinsic takes MDNode arguments, verify that they are either global |
| 5196 |
// or are local to *this* function. |
5196 |
// or are local to *this* function. |
| 5197 |
for (Value *V : Call.args()) { |
5197 |
for (Value *V : Call.args()) { |
| 5198 |
if (auto *MD = dyn_cast(V)) |
5198 |
if (auto *MD = dyn_cast(V)) |
| 5199 |
visitMetadataAsValue(*MD, Call.getCaller()); |
5199 |
visitMetadataAsValue(*MD, Call.getCaller()); |
| 5200 |
if (auto *Const = dyn_cast(V)) |
5200 |
if (auto *Const = dyn_cast(V)) |
| 5201 |
Check(!Const->getType()->isX86_AMXTy(), |
5201 |
Check(!Const->getType()->isX86_AMXTy(), |
| 5202 |
"const x86_amx is not allowed in argument!"); |
5202 |
"const x86_amx is not allowed in argument!"); |
| 5203 |
} |
5203 |
} |
| 5204 |
|
5204 |
|
| 5205 |
switch (ID) { |
5205 |
switch (ID) { |
| 5206 |
default: |
5206 |
default: |
| 5207 |
break; |
5207 |
break; |
| 5208 |
case Intrinsic::assume: { |
5208 |
case Intrinsic::assume: { |
| 5209 |
for (auto &Elem : Call.bundle_op_infos()) { |
5209 |
for (auto &Elem : Call.bundle_op_infos()) { |
| 5210 |
unsigned ArgCount = Elem.End - Elem.Begin; |
5210 |
unsigned ArgCount = Elem.End - Elem.Begin; |
| 5211 |
// Separate storage assumptions are special insofar as they're the only |
5211 |
// Separate storage assumptions are special insofar as they're the only |
| 5212 |
// operand bundles allowed on assumes that aren't parameter attributes. |
5212 |
// operand bundles allowed on assumes that aren't parameter attributes. |
| 5213 |
if (Elem.Tag->getKey() == "separate_storage") { |
5213 |
if (Elem.Tag->getKey() == "separate_storage") { |
| 5214 |
Check(ArgCount == 2, |
5214 |
Check(ArgCount == 2, |
| 5215 |
"separate_storage assumptions should have 2 arguments", Call); |
5215 |
"separate_storage assumptions should have 2 arguments", Call); |
| 5216 |
Check(Call.getOperand(Elem.Begin)->getType()->isPointerTy() && |
5216 |
Check(Call.getOperand(Elem.Begin)->getType()->isPointerTy() && |
| 5217 |
Call.getOperand(Elem.Begin + 1)->getType()->isPointerTy(), |
5217 |
Call.getOperand(Elem.Begin + 1)->getType()->isPointerTy(), |
| 5218 |
"arguments to separate_storage assumptions should be pointers", |
5218 |
"arguments to separate_storage assumptions should be pointers", |
| 5219 |
Call); |
5219 |
Call); |
| 5220 |
return; |
5220 |
return; |
| 5221 |
} |
5221 |
} |
| 5222 |
Check(Elem.Tag->getKey() == "ignore" || |
5222 |
Check(Elem.Tag->getKey() == "ignore" || |
| 5223 |
Attribute::isExistingAttribute(Elem.Tag->getKey()), |
5223 |
Attribute::isExistingAttribute(Elem.Tag->getKey()), |
| 5224 |
"tags must be valid attribute names", Call); |
5224 |
"tags must be valid attribute names", Call); |
| 5225 |
Attribute::AttrKind Kind = |
5225 |
Attribute::AttrKind Kind = |
| 5226 |
Attribute::getAttrKindFromName(Elem.Tag->getKey()); |
5226 |
Attribute::getAttrKindFromName(Elem.Tag->getKey()); |
| 5227 |
if (Kind == Attribute::Alignment) { |
5227 |
if (Kind == Attribute::Alignment) { |
| 5228 |
Check(ArgCount <= 3 && ArgCount >= 2, |
5228 |
Check(ArgCount <= 3 && ArgCount >= 2, |
| 5229 |
"alignment assumptions should have 2 or 3 arguments", Call); |
5229 |
"alignment assumptions should have 2 or 3 arguments", Call); |
| 5230 |
Check(Call.getOperand(Elem.Begin)->getType()->isPointerTy(), |
5230 |
Check(Call.getOperand(Elem.Begin)->getType()->isPointerTy(), |
| 5231 |
"first argument should be a pointer", Call); |
5231 |
"first argument should be a pointer", Call); |
| 5232 |
Check(Call.getOperand(Elem.Begin + 1)->getType()->isIntegerTy(), |
5232 |
Check(Call.getOperand(Elem.Begin + 1)->getType()->isIntegerTy(), |
| 5233 |
"second argument should be an integer", Call); |
5233 |
"second argument should be an integer", Call); |
| 5234 |
if (ArgCount == 3) |
5234 |
if (ArgCount == 3) |
| 5235 |
Check(Call.getOperand(Elem.Begin + 2)->getType()->isIntegerTy(), |
5235 |
Check(Call.getOperand(Elem.Begin + 2)->getType()->isIntegerTy(), |
| 5236 |
"third argument should be an integer if present", Call); |
5236 |
"third argument should be an integer if present", Call); |
| 5237 |
return; |
5237 |
return; |
| 5238 |
} |
5238 |
} |
| 5239 |
Check(ArgCount <= 2, "too many arguments", Call); |
5239 |
Check(ArgCount <= 2, "too many arguments", Call); |
| 5240 |
if (Kind == Attribute::None) |
5240 |
if (Kind == Attribute::None) |
| 5241 |
break; |
5241 |
break; |
| 5242 |
if (Attribute::isIntAttrKind(Kind)) { |
5242 |
if (Attribute::isIntAttrKind(Kind)) { |
| 5243 |
Check(ArgCount == 2, "this attribute should have 2 arguments", Call); |
5243 |
Check(ArgCount == 2, "this attribute should have 2 arguments", Call); |
| 5244 |
Check(isa(Call.getOperand(Elem.Begin + 1)), |
5244 |
Check(isa(Call.getOperand(Elem.Begin + 1)), |
| 5245 |
"the second argument should be a constant integral value", Call); |
5245 |
"the second argument should be a constant integral value", Call); |
| 5246 |
} else if (Attribute::canUseAsParamAttr(Kind)) { |
5246 |
} else if (Attribute::canUseAsParamAttr(Kind)) { |
| 5247 |
Check((ArgCount) == 1, "this attribute should have one argument", Call); |
5247 |
Check((ArgCount) == 1, "this attribute should have one argument", Call); |
| 5248 |
} else if (Attribute::canUseAsFnAttr(Kind)) { |
5248 |
} else if (Attribute::canUseAsFnAttr(Kind)) { |
| 5249 |
Check((ArgCount) == 0, "this attribute has no argument", Call); |
5249 |
Check((ArgCount) == 0, "this attribute has no argument", Call); |
| 5250 |
} |
5250 |
} |
| 5251 |
} |
5251 |
} |
| 5252 |
break; |
5252 |
break; |
| 5253 |
} |
5253 |
} |
| 5254 |
case Intrinsic::coro_id: { |
5254 |
case Intrinsic::coro_id: { |
| 5255 |
auto *InfoArg = Call.getArgOperand(3)->stripPointerCasts(); |
5255 |
auto *InfoArg = Call.getArgOperand(3)->stripPointerCasts(); |
| 5256 |
if (isa(InfoArg)) |
5256 |
if (isa(InfoArg)) |
| 5257 |
break; |
5257 |
break; |
| 5258 |
auto *GV = dyn_cast(InfoArg); |
5258 |
auto *GV = dyn_cast(InfoArg); |
| 5259 |
Check(GV && GV->isConstant() && GV->hasDefinitiveInitializer(), |
5259 |
Check(GV && GV->isConstant() && GV->hasDefinitiveInitializer(), |
| 5260 |
"info argument of llvm.coro.id must refer to an initialized " |
5260 |
"info argument of llvm.coro.id must refer to an initialized " |
| 5261 |
"constant"); |
5261 |
"constant"); |
| 5262 |
Constant *Init = GV->getInitializer(); |
5262 |
Constant *Init = GV->getInitializer(); |
| 5263 |
Check(isa(Init) || isa(Init), |
5263 |
Check(isa(Init) || isa(Init), |
| 5264 |
"info argument of llvm.coro.id must refer to either a struct or " |
5264 |
"info argument of llvm.coro.id must refer to either a struct or " |
| 5265 |
"an array"); |
5265 |
"an array"); |
| 5266 |
break; |
5266 |
break; |
| 5267 |
} |
5267 |
} |
| 5268 |
case Intrinsic::is_fpclass: { |
5268 |
case Intrinsic::is_fpclass: { |
| 5269 |
const ConstantInt *TestMask = cast(Call.getOperand(1)); |
5269 |
const ConstantInt *TestMask = cast(Call.getOperand(1)); |
| 5270 |
Check((TestMask->getZExtValue() & ~static_cast(fcAllFlags)) == 0, |
5270 |
Check((TestMask->getZExtValue() & ~static_cast(fcAllFlags)) == 0, |
| 5271 |
"unsupported bits for llvm.is.fpclass test mask"); |
5271 |
"unsupported bits for llvm.is.fpclass test mask"); |
| 5272 |
break; |
5272 |
break; |
| 5273 |
} |
5273 |
} |
| 5274 |
case Intrinsic::fptrunc_round: { |
5274 |
case Intrinsic::fptrunc_round: { |
| 5275 |
// Check the rounding mode |
5275 |
// Check the rounding mode |
| 5276 |
Metadata *MD = nullptr; |
5276 |
Metadata *MD = nullptr; |
| 5277 |
auto *MAV = dyn_cast(Call.getOperand(1)); |
5277 |
auto *MAV = dyn_cast(Call.getOperand(1)); |
| 5278 |
if (MAV) |
5278 |
if (MAV) |
| 5279 |
MD = MAV->getMetadata(); |
5279 |
MD = MAV->getMetadata(); |
| 5280 |
|
5280 |
|
| 5281 |
Check(MD != nullptr, "missing rounding mode argument", Call); |
5281 |
Check(MD != nullptr, "missing rounding mode argument", Call); |
| 5282 |
|
5282 |
|
| 5283 |
Check(isa(MD), |
5283 |
Check(isa(MD), |
| 5284 |
("invalid value for llvm.fptrunc.round metadata operand" |
5284 |
("invalid value for llvm.fptrunc.round metadata operand" |
| 5285 |
" (the operand should be a string)"), |
5285 |
" (the operand should be a string)"), |
| 5286 |
MD); |
5286 |
MD); |
| 5287 |
|
5287 |
|
| 5288 |
std::optional RoundMode = |
5288 |
std::optional RoundMode = |
| 5289 |
convertStrToRoundingMode(cast(MD)->getString()); |
5289 |
convertStrToRoundingMode(cast(MD)->getString()); |
| 5290 |
Check(RoundMode && *RoundMode != RoundingMode::Dynamic, |
5290 |
Check(RoundMode && *RoundMode != RoundingMode::Dynamic, |
| 5291 |
"unsupported rounding mode argument", Call); |
5291 |
"unsupported rounding mode argument", Call); |
| 5292 |
break; |
5292 |
break; |
| 5293 |
} |
5293 |
} |
| 5294 |
#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID: |
5294 |
#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...) case Intrinsic::VPID: |
| 5295 |
#include "llvm/IR/VPIntrinsics.def" |
5295 |
#include "llvm/IR/VPIntrinsics.def" |
| 5296 |
visitVPIntrinsic(cast(Call)); |
5296 |
visitVPIntrinsic(cast(Call)); |
| 5297 |
break; |
5297 |
break; |
| 5298 |
#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \ |
5298 |
#define INSTRUCTION(NAME, NARGS, ROUND_MODE, INTRINSIC) \ |
| 5299 |
case Intrinsic::INTRINSIC: |
5299 |
case Intrinsic::INTRINSIC: |
| 5300 |
#include "llvm/IR/ConstrainedOps.def" |
5300 |
#include "llvm/IR/ConstrainedOps.def" |
| 5301 |
visitConstrainedFPIntrinsic(cast(Call)); |
5301 |
visitConstrainedFPIntrinsic(cast(Call)); |
| 5302 |
break; |
5302 |
break; |
| 5303 |
case Intrinsic::dbg_declare: // llvm.dbg.declare |
5303 |
case Intrinsic::dbg_declare: // llvm.dbg.declare |
| 5304 |
Check(isa(Call.getArgOperand(0)), |
5304 |
Check(isa(Call.getArgOperand(0)), |
| 5305 |
"invalid llvm.dbg.declare intrinsic call 1", Call); |
5305 |
"invalid llvm.dbg.declare intrinsic call 1", Call); |
| 5306 |
visitDbgIntrinsic("declare", cast(Call)); |
5306 |
visitDbgIntrinsic("declare", cast(Call)); |
| 5307 |
break; |
5307 |
break; |
| 5308 |
case Intrinsic::dbg_value: // llvm.dbg.value |
5308 |
case Intrinsic::dbg_value: // llvm.dbg.value |
| 5309 |
visitDbgIntrinsic("value", cast(Call)); |
5309 |
visitDbgIntrinsic("value", cast(Call)); |
| 5310 |
break; |
5310 |
break; |
| 5311 |
case Intrinsic::dbg_assign: // llvm.dbg.assign |
5311 |
case Intrinsic::dbg_assign: // llvm.dbg.assign |
| 5312 |
visitDbgIntrinsic("assign", cast(Call)); |
5312 |
visitDbgIntrinsic("assign", cast(Call)); |
| 5313 |
break; |
5313 |
break; |
| 5314 |
case Intrinsic::dbg_label: // llvm.dbg.label |
5314 |
case Intrinsic::dbg_label: // llvm.dbg.label |
| 5315 |
visitDbgLabelIntrinsic("label", cast(Call)); |
5315 |
visitDbgLabelIntrinsic("label", cast(Call)); |
| 5316 |
break; |
5316 |
break; |
| 5317 |
case Intrinsic::memcpy: |
5317 |
case Intrinsic::memcpy: |
| 5318 |
case Intrinsic::memcpy_inline: |
5318 |
case Intrinsic::memcpy_inline: |
| 5319 |
case Intrinsic::memmove: |
5319 |
case Intrinsic::memmove: |
| 5320 |
case Intrinsic::memset: |
5320 |
case Intrinsic::memset: |
| 5321 |
case Intrinsic::memset_inline: { |
5321 |
case Intrinsic::memset_inline: { |
| 5322 |
break; |
5322 |
break; |
| 5323 |
} |
5323 |
} |
| 5324 |
case Intrinsic::memcpy_element_unordered_atomic: |
5324 |
case Intrinsic::memcpy_element_unordered_atomic: |
| 5325 |
case Intrinsic::memmove_element_unordered_atomic: |
5325 |
case Intrinsic::memmove_element_unordered_atomic: |
| 5326 |
case Intrinsic::memset_element_unordered_atomic: { |
5326 |
case Intrinsic::memset_element_unordered_atomic: { |
| 5327 |
const auto *AMI = cast(&Call); |
5327 |
const auto *AMI = cast(&Call); |
| 5328 |
|
5328 |
|
| 5329 |
ConstantInt *ElementSizeCI = |
5329 |
ConstantInt *ElementSizeCI = |
| 5330 |
cast(AMI->getRawElementSizeInBytes()); |
5330 |
cast(AMI->getRawElementSizeInBytes()); |
| 5331 |
const APInt &ElementSizeVal = ElementSizeCI->getValue(); |
5331 |
const APInt &ElementSizeVal = ElementSizeCI->getValue(); |
| 5332 |
Check(ElementSizeVal.isPowerOf2(), |
5332 |
Check(ElementSizeVal.isPowerOf2(), |
| 5333 |
"element size of the element-wise atomic memory intrinsic " |
5333 |
"element size of the element-wise atomic memory intrinsic " |
| 5334 |
"must be a power of 2", |
5334 |
"must be a power of 2", |
| 5335 |
Call); |
5335 |
Call); |
| 5336 |
|
5336 |
|
| 5337 |
auto IsValidAlignment = [&](MaybeAlign Alignment) { |
5337 |
auto IsValidAlignment = [&](MaybeAlign Alignment) { |
| 5338 |
return Alignment && ElementSizeVal.ule(Alignment->value()); |
5338 |
return Alignment && ElementSizeVal.ule(Alignment->value()); |
| 5339 |
}; |
5339 |
}; |
| 5340 |
Check(IsValidAlignment(AMI->getDestAlign()), |
5340 |
Check(IsValidAlignment(AMI->getDestAlign()), |
| 5341 |
"incorrect alignment of the destination argument", Call); |
5341 |
"incorrect alignment of the destination argument", Call); |
| 5342 |
if (const auto *AMT = dyn_cast(AMI)) { |
5342 |
if (const auto *AMT = dyn_cast(AMI)) { |
| 5343 |
Check(IsValidAlignment(AMT->getSourceAlign()), |
5343 |
Check(IsValidAlignment(AMT->getSourceAlign()), |
| 5344 |
"incorrect alignment of the source argument", Call); |
5344 |
"incorrect alignment of the source argument", Call); |
| 5345 |
} |
5345 |
} |
| 5346 |
break; |
5346 |
break; |
| 5347 |
} |
5347 |
} |
| 5348 |
case Intrinsic::call_preallocated_setup: { |
5348 |
case Intrinsic::call_preallocated_setup: { |
| 5349 |
auto *NumArgs = dyn_cast(Call.getArgOperand(0)); |
5349 |
auto *NumArgs = dyn_cast(Call.getArgOperand(0)); |
| 5350 |
Check(NumArgs != nullptr, |
5350 |
Check(NumArgs != nullptr, |
| 5351 |
"llvm.call.preallocated.setup argument must be a constant"); |
5351 |
"llvm.call.preallocated.setup argument must be a constant"); |
| 5352 |
bool FoundCall = false; |
5352 |
bool FoundCall = false; |
| 5353 |
for (User *U : Call.users()) { |
5353 |
for (User *U : Call.users()) { |
| 5354 |
auto *UseCall = dyn_cast(U); |
5354 |
auto *UseCall = dyn_cast(U); |
| 5355 |
Check(UseCall != nullptr, |
5355 |
Check(UseCall != nullptr, |
| 5356 |
"Uses of llvm.call.preallocated.setup must be calls"); |
5356 |
"Uses of llvm.call.preallocated.setup must be calls"); |
| 5357 |
const Function *Fn = UseCall->getCalledFunction(); |
5357 |
const Function *Fn = UseCall->getCalledFunction(); |
| 5358 |
if (Fn && Fn->getIntrinsicID() == Intrinsic::call_preallocated_arg) { |
5358 |
if (Fn && Fn->getIntrinsicID() == Intrinsic::call_preallocated_arg) { |
| 5359 |
auto *AllocArgIndex = dyn_cast(UseCall->getArgOperand(1)); |
5359 |
auto *AllocArgIndex = dyn_cast(UseCall->getArgOperand(1)); |
| 5360 |
Check(AllocArgIndex != nullptr, |
5360 |
Check(AllocArgIndex != nullptr, |
| 5361 |
"llvm.call.preallocated.alloc arg index must be a constant"); |
5361 |
"llvm.call.preallocated.alloc arg index must be a constant"); |
| 5362 |
auto AllocArgIndexInt = AllocArgIndex->getValue(); |
5362 |
auto AllocArgIndexInt = AllocArgIndex->getValue(); |
| 5363 |
Check(AllocArgIndexInt.sge(0) && |
5363 |
Check(AllocArgIndexInt.sge(0) && |
| 5364 |
AllocArgIndexInt.slt(NumArgs->getValue()), |
5364 |
AllocArgIndexInt.slt(NumArgs->getValue()), |
| 5365 |
"llvm.call.preallocated.alloc arg index must be between 0 and " |
5365 |
"llvm.call.preallocated.alloc arg index must be between 0 and " |
| 5366 |
"corresponding " |
5366 |
"corresponding " |
| 5367 |
"llvm.call.preallocated.setup's argument count"); |
5367 |
"llvm.call.preallocated.setup's argument count"); |
| 5368 |
} else if (Fn && Fn->getIntrinsicID() == |
5368 |
} else if (Fn && Fn->getIntrinsicID() == |
| 5369 |
Intrinsic::call_preallocated_teardown) { |
5369 |
Intrinsic::call_preallocated_teardown) { |
| 5370 |
// nothing to do |
5370 |
// nothing to do |
| 5371 |
} else { |
5371 |
} else { |
| 5372 |
Check(!FoundCall, "Can have at most one call corresponding to a " |
5372 |
Check(!FoundCall, "Can have at most one call corresponding to a " |
| 5373 |
"llvm.call.preallocated.setup"); |
5373 |
"llvm.call.preallocated.setup"); |
| 5374 |
FoundCall = true; |
5374 |
FoundCall = true; |
| 5375 |
size_t NumPreallocatedArgs = 0; |
5375 |
size_t NumPreallocatedArgs = 0; |
| 5376 |
for (unsigned i = 0; i < UseCall->arg_size(); i++) { |
5376 |
for (unsigned i = 0; i < UseCall->arg_size(); i++) { |
| 5377 |
if (UseCall->paramHasAttr(i, Attribute::Preallocated)) { |
5377 |
if (UseCall->paramHasAttr(i, Attribute::Preallocated)) { |
| 5378 |
++NumPreallocatedArgs; |
5378 |
++NumPreallocatedArgs; |
| 5379 |
} |
5379 |
} |
| 5380 |
} |
5380 |
} |
| 5381 |
Check(NumPreallocatedArgs != 0, |
5381 |
Check(NumPreallocatedArgs != 0, |
| 5382 |
"cannot use preallocated intrinsics on a call without " |
5382 |
"cannot use preallocated intrinsics on a call without " |
| 5383 |
"preallocated arguments"); |
5383 |
"preallocated arguments"); |
| 5384 |
Check(NumArgs->equalsInt(NumPreallocatedArgs), |
5384 |
Check(NumArgs->equalsInt(NumPreallocatedArgs), |
| 5385 |
"llvm.call.preallocated.setup arg size must be equal to number " |
5385 |
"llvm.call.preallocated.setup arg size must be equal to number " |
| 5386 |
"of preallocated arguments " |
5386 |
"of preallocated arguments " |
| 5387 |
"at call site", |
5387 |
"at call site", |
| 5388 |
Call, *UseCall); |
5388 |
Call, *UseCall); |
| 5389 |
// getOperandBundle() cannot be called if more than one of the operand |
5389 |
// getOperandBundle() cannot be called if more than one of the operand |
| 5390 |
// bundle exists. There is already a check elsewhere for this, so skip |
5390 |
// bundle exists. There is already a check elsewhere for this, so skip |
| 5391 |
// here if we see more than one. |
5391 |
// here if we see more than one. |
| 5392 |
if (UseCall->countOperandBundlesOfType(LLVMContext::OB_preallocated) > |
5392 |
if (UseCall->countOperandBundlesOfType(LLVMContext::OB_preallocated) > |
| 5393 |
1) { |
5393 |
1) { |
| 5394 |
return; |
5394 |
return; |
| 5395 |
} |
5395 |
} |
| 5396 |
auto PreallocatedBundle = |
5396 |
auto PreallocatedBundle = |
| 5397 |
UseCall->getOperandBundle(LLVMContext::OB_preallocated); |
5397 |
UseCall->getOperandBundle(LLVMContext::OB_preallocated); |
| 5398 |
Check(PreallocatedBundle, |
5398 |
Check(PreallocatedBundle, |
| 5399 |
"Use of llvm.call.preallocated.setup outside intrinsics " |
5399 |
"Use of llvm.call.preallocated.setup outside intrinsics " |
| 5400 |
"must be in \"preallocated\" operand bundle"); |
5400 |
"must be in \"preallocated\" operand bundle"); |
| 5401 |
Check(PreallocatedBundle->Inputs.front().get() == &Call, |
5401 |
Check(PreallocatedBundle->Inputs.front().get() == &Call, |
| 5402 |
"preallocated bundle must have token from corresponding " |
5402 |
"preallocated bundle must have token from corresponding " |
| 5403 |
"llvm.call.preallocated.setup"); |
5403 |
"llvm.call.preallocated.setup"); |
| 5404 |
} |
5404 |
} |
| 5405 |
} |
5405 |
} |
| 5406 |
break; |
5406 |
break; |
| 5407 |
} |
5407 |
} |
| 5408 |
case Intrinsic::call_preallocated_arg: { |
5408 |
case Intrinsic::call_preallocated_arg: { |
| 5409 |
auto *Token = dyn_cast(Call.getArgOperand(0)); |
5409 |
auto *Token = dyn_cast(Call.getArgOperand(0)); |
| 5410 |
Check(Token && Token->getCalledFunction()->getIntrinsicID() == |
5410 |
Check(Token && Token->getCalledFunction()->getIntrinsicID() == |
| 5411 |
Intrinsic::call_preallocated_setup, |
5411 |
Intrinsic::call_preallocated_setup, |
| 5412 |
"llvm.call.preallocated.arg token argument must be a " |
5412 |
"llvm.call.preallocated.arg token argument must be a " |
| 5413 |
"llvm.call.preallocated.setup"); |
5413 |
"llvm.call.preallocated.setup"); |
| 5414 |
Check(Call.hasFnAttr(Attribute::Preallocated), |
5414 |
Check(Call.hasFnAttr(Attribute::Preallocated), |
| 5415 |
"llvm.call.preallocated.arg must be called with a \"preallocated\" " |
5415 |
"llvm.call.preallocated.arg must be called with a \"preallocated\" " |
| 5416 |
"call site attribute"); |
5416 |
"call site attribute"); |
| 5417 |
break; |
5417 |
break; |
| 5418 |
} |
5418 |
} |
| 5419 |
case Intrinsic::call_preallocated_teardown: { |
5419 |
case Intrinsic::call_preallocated_teardown: { |
| 5420 |
auto *Token = dyn_cast(Call.getArgOperand(0)); |
5420 |
auto *Token = dyn_cast(Call.getArgOperand(0)); |
| 5421 |
Check(Token && Token->getCalledFunction()->getIntrinsicID() == |
5421 |
Check(Token && Token->getCalledFunction()->getIntrinsicID() == |
| 5422 |
Intrinsic::call_preallocated_setup, |
5422 |
Intrinsic::call_preallocated_setup, |
| 5423 |
"llvm.call.preallocated.teardown token argument must be a " |
5423 |
"llvm.call.preallocated.teardown token argument must be a " |
| 5424 |
"llvm.call.preallocated.setup"); |
5424 |
"llvm.call.preallocated.setup"); |
| 5425 |
break; |
5425 |
break; |
| 5426 |
} |
5426 |
} |
| 5427 |
case Intrinsic::gcroot: |
5427 |
case Intrinsic::gcroot: |
| 5428 |
case Intrinsic::gcwrite: |
5428 |
case Intrinsic::gcwrite: |
| 5429 |
case Intrinsic::gcread: |
5429 |
case Intrinsic::gcread: |
| 5430 |
if (ID == Intrinsic::gcroot) { |
5430 |
if (ID == Intrinsic::gcroot) { |
| 5431 |
AllocaInst *AI = |
5431 |
AllocaInst *AI = |
| 5432 |
dyn_cast(Call.getArgOperand(0)->stripPointerCasts()); |
5432 |
dyn_cast(Call.getArgOperand(0)->stripPointerCasts()); |
| 5433 |
Check(AI, "llvm.gcroot parameter #1 must be an alloca.", Call); |
5433 |
Check(AI, "llvm.gcroot parameter #1 must be an alloca.", Call); |
| 5434 |
Check(isa(Call.getArgOperand(1)), |
5434 |
Check(isa(Call.getArgOperand(1)), |
| 5435 |
"llvm.gcroot parameter #2 must be a constant.", Call); |
5435 |
"llvm.gcroot parameter #2 must be a constant.", Call); |
| 5436 |
if (!AI->getAllocatedType()->isPointerTy()) { |
5436 |
if (!AI->getAllocatedType()->isPointerTy()) { |
| 5437 |
Check(!isa(Call.getArgOperand(1)), |
5437 |
Check(!isa(Call.getArgOperand(1)), |
| 5438 |
"llvm.gcroot parameter #1 must either be a pointer alloca, " |
5438 |
"llvm.gcroot parameter #1 must either be a pointer alloca, " |
| 5439 |
"or argument #2 must be a non-null constant.", |
5439 |
"or argument #2 must be a non-null constant.", |
| 5440 |
Call); |
5440 |
Call); |
| 5441 |
} |
5441 |
} |
| 5442 |
} |
5442 |
} |
| 5443 |
|
5443 |
|
| 5444 |
Check(Call.getParent()->getParent()->hasGC(), |
5444 |
Check(Call.getParent()->getParent()->hasGC(), |
| 5445 |
"Enclosing function does not use GC.", Call); |
5445 |
"Enclosing function does not use GC.", Call); |
| 5446 |
break; |
5446 |
break; |
| 5447 |
case Intrinsic::init_trampoline: |
5447 |
case Intrinsic::init_trampoline: |
| 5448 |
Check(isa(Call.getArgOperand(1)->stripPointerCasts()), |
5448 |
Check(isa(Call.getArgOperand(1)->stripPointerCasts()), |
| 5449 |
"llvm.init_trampoline parameter #2 must resolve to a function.", |
5449 |
"llvm.init_trampoline parameter #2 must resolve to a function.", |
| 5450 |
Call); |
5450 |
Call); |
| 5451 |
break; |
5451 |
break; |
| 5452 |
case Intrinsic::prefetch: |
5452 |
case Intrinsic::prefetch: |
| 5453 |
Check(cast(Call.getArgOperand(1))->getZExtValue() < 2, |
5453 |
Check(cast(Call.getArgOperand(1))->getZExtValue() < 2, |
| 5454 |
"rw argument to llvm.prefetch must be 0-1", Call); |
5454 |
"rw argument to llvm.prefetch must be 0-1", Call); |
| 5455 |
Check(cast(Call.getArgOperand(2))->getZExtValue() < 4, |
5455 |
Check(cast(Call.getArgOperand(2))->getZExtValue() < 4, |
| 5456 |
"locality argument to llvm.prefetch must be 0-4", Call); |
5456 |
"locality argument to llvm.prefetch must be 0-4", Call); |
| 5457 |
Check(cast(Call.getArgOperand(3))->getZExtValue() < 2, |
5457 |
Check(cast(Call.getArgOperand(3))->getZExtValue() < 2, |
| 5458 |
"cache type argument to llvm.prefetch must be 0-1", Call); |
5458 |
"cache type argument to llvm.prefetch must be 0-1", Call); |
| 5459 |
break; |
5459 |
break; |
| 5460 |
case Intrinsic::stackprotector: |
5460 |
case Intrinsic::stackprotector: |
| 5461 |
Check(isa(Call.getArgOperand(1)->stripPointerCasts()), |
5461 |
Check(isa(Call.getArgOperand(1)->stripPointerCasts()), |
| 5462 |
"llvm.stackprotector parameter #2 must resolve to an alloca.", Call); |
5462 |
"llvm.stackprotector parameter #2 must resolve to an alloca.", Call); |
| 5463 |
break; |
5463 |
break; |
| 5464 |
case Intrinsic::localescape: { |
5464 |
case Intrinsic::localescape: { |
| 5465 |
BasicBlock *BB = Call.getParent(); |
5465 |
BasicBlock *BB = Call.getParent(); |
| 5466 |
Check(BB->isEntryBlock(), "llvm.localescape used outside of entry block", |
5466 |
Check(BB->isEntryBlock(), "llvm.localescape used outside of entry block", |
| 5467 |
Call); |
5467 |
Call); |
| 5468 |
Check(!SawFrameEscape, "multiple calls to llvm.localescape in one function", |
5468 |
Check(!SawFrameEscape, "multiple calls to llvm.localescape in one function", |
| 5469 |
Call); |
5469 |
Call); |
| 5470 |
for (Value *Arg : Call.args()) { |
5470 |
for (Value *Arg : Call.args()) { |
| 5471 |
if (isa(Arg)) |
5471 |
if (isa(Arg)) |
| 5472 |
continue; // Null values are allowed as placeholders. |
5472 |
continue; // Null values are allowed as placeholders. |
| 5473 |
auto *AI = dyn_cast(Arg->stripPointerCasts()); |
5473 |
auto *AI = dyn_cast(Arg->stripPointerCasts()); |
| 5474 |
Check(AI && AI->isStaticAlloca(), |
5474 |
Check(AI && AI->isStaticAlloca(), |
| 5475 |
"llvm.localescape only accepts static allocas", Call); |
5475 |
"llvm.localescape only accepts static allocas", Call); |
| 5476 |
} |
5476 |
} |
| 5477 |
FrameEscapeInfo[BB->getParent()].first = Call.arg_size(); |
5477 |
FrameEscapeInfo[BB->getParent()].first = Call.arg_size(); |
| 5478 |
SawFrameEscape = true; |
5478 |
SawFrameEscape = true; |
| 5479 |
break; |
5479 |
break; |
| 5480 |
} |
5480 |
} |
| 5481 |
case Intrinsic::localrecover: { |
5481 |
case Intrinsic::localrecover: { |
| 5482 |
Value *FnArg = Call.getArgOperand(0)->stripPointerCasts(); |
5482 |
Value *FnArg = Call.getArgOperand(0)->stripPointerCasts(); |
| 5483 |
Function *Fn = dyn_cast(FnArg); |
5483 |
Function *Fn = dyn_cast(FnArg); |
| 5484 |
Check(Fn && !Fn->isDeclaration(), |
5484 |
Check(Fn && !Fn->isDeclaration(), |
| 5485 |
"llvm.localrecover first " |
5485 |
"llvm.localrecover first " |
| 5486 |
"argument must be function defined in this module", |
5486 |
"argument must be function defined in this module", |
| 5487 |
Call); |
5487 |
Call); |
| 5488 |
auto *IdxArg = cast(Call.getArgOperand(2)); |
5488 |
auto *IdxArg = cast(Call.getArgOperand(2)); |
| 5489 |
auto &Entry = FrameEscapeInfo[Fn]; |
5489 |
auto &Entry = FrameEscapeInfo[Fn]; |
| 5490 |
Entry.second = unsigned( |
5490 |
Entry.second = unsigned( |
| 5491 |
std::max(uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1)); |
5491 |
std::max(uint64_t(Entry.second), IdxArg->getLimitedValue(~0U) + 1)); |
| 5492 |
break; |
5492 |
break; |
| 5493 |
} |
5493 |
} |
| 5494 |
|
5494 |
|
| 5495 |
case Intrinsic::experimental_gc_statepoint: |
5495 |
case Intrinsic::experimental_gc_statepoint: |
| 5496 |
if (auto *CI = dyn_cast(&Call)) |
5496 |
if (auto *CI = dyn_cast(&Call)) |
| 5497 |
Check(!CI->isInlineAsm(), |
5497 |
Check(!CI->isInlineAsm(), |
| 5498 |
"gc.statepoint support for inline assembly unimplemented", CI); |
5498 |
"gc.statepoint support for inline assembly unimplemented", CI); |
| 5499 |
Check(Call.getParent()->getParent()->hasGC(), |
5499 |
Check(Call.getParent()->getParent()->hasGC(), |
| 5500 |
"Enclosing function does not use GC.", Call); |
5500 |
"Enclosing function does not use GC.", Call); |
| 5501 |
|
5501 |
|
| 5502 |
verifyStatepoint(Call); |
5502 |
verifyStatepoint(Call); |
| 5503 |
break; |
5503 |
break; |
| 5504 |
case Intrinsic::experimental_gc_result: { |
5504 |
case Intrinsic::experimental_gc_result: { |
| 5505 |
Check(Call.getParent()->getParent()->hasGC(), |
5505 |
Check(Call.getParent()->getParent()->hasGC(), |
| 5506 |
"Enclosing function does not use GC.", Call); |
5506 |
"Enclosing function does not use GC.", Call); |
| 5507 |
|
5507 |
|
| 5508 |
auto *Statepoint = Call.getArgOperand(0); |
5508 |
auto *Statepoint = Call.getArgOperand(0); |
| 5509 |
if (isa(Statepoint)) |
5509 |
if (isa(Statepoint)) |
| 5510 |
break; |
5510 |
break; |
| 5511 |
|
5511 |
|
| 5512 |
// Are we tied to a statepoint properly? |
5512 |
// Are we tied to a statepoint properly? |
| 5513 |
const auto *StatepointCall = dyn_cast(Statepoint); |
5513 |
const auto *StatepointCall = dyn_cast(Statepoint); |
| 5514 |
const Function *StatepointFn = |
5514 |
const Function *StatepointFn = |
| 5515 |
StatepointCall ? StatepointCall->getCalledFunction() : nullptr; |
5515 |
StatepointCall ? StatepointCall->getCalledFunction() : nullptr; |
| 5516 |
Check(StatepointFn && StatepointFn->isDeclaration() && |
5516 |
Check(StatepointFn && StatepointFn->isDeclaration() && |
| 5517 |
StatepointFn->getIntrinsicID() == |
5517 |
StatepointFn->getIntrinsicID() == |
| 5518 |
Intrinsic::experimental_gc_statepoint, |
5518 |
Intrinsic::experimental_gc_statepoint, |
| 5519 |
"gc.result operand #1 must be from a statepoint", Call, |
5519 |
"gc.result operand #1 must be from a statepoint", Call, |
| 5520 |
Call.getArgOperand(0)); |
5520 |
Call.getArgOperand(0)); |
| 5521 |
|
5521 |
|
| 5522 |
// Check that result type matches wrapped callee. |
5522 |
// Check that result type matches wrapped callee. |
| 5523 |
auto *TargetFuncType = |
5523 |
auto *TargetFuncType = |
| 5524 |
cast(StatepointCall->getParamElementType(2)); |
5524 |
cast(StatepointCall->getParamElementType(2)); |
| 5525 |
Check(Call.getType() == TargetFuncType->getReturnType(), |
5525 |
Check(Call.getType() == TargetFuncType->getReturnType(), |
| 5526 |
"gc.result result type does not match wrapped callee", Call); |
5526 |
"gc.result result type does not match wrapped callee", Call); |
| 5527 |
break; |
5527 |
break; |
| 5528 |
} |
5528 |
} |
| 5529 |
case Intrinsic::experimental_gc_relocate: { |
5529 |
case Intrinsic::experimental_gc_relocate: { |
| 5530 |
Check(Call.arg_size() == 3, "wrong number of arguments", Call); |
5530 |
Check(Call.arg_size() == 3, "wrong number of arguments", Call); |
| 5531 |
|
5531 |
|
| 5532 |
Check(isa(Call.getType()->getScalarType()), |
5532 |
Check(isa(Call.getType()->getScalarType()), |
| 5533 |
"gc.relocate must return a pointer or a vector of pointers", Call); |
5533 |
"gc.relocate must return a pointer or a vector of pointers", Call); |
| 5534 |
|
5534 |
|
| 5535 |
// Check that this relocate is correctly tied to the statepoint |
5535 |
// Check that this relocate is correctly tied to the statepoint |
| 5536 |
|
5536 |
|
| 5537 |
// This is case for relocate on the unwinding path of an invoke statepoint |
5537 |
// This is case for relocate on the unwinding path of an invoke statepoint |
| 5538 |
if (LandingPadInst *LandingPad = |
5538 |
if (LandingPadInst *LandingPad = |
| 5539 |
dyn_cast(Call.getArgOperand(0))) { |
5539 |
dyn_cast(Call.getArgOperand(0))) { |
| 5540 |
|
5540 |
|
| 5541 |
const BasicBlock *InvokeBB = |
5541 |
const BasicBlock *InvokeBB = |
| 5542 |
LandingPad->getParent()->getUniquePredecessor(); |
5542 |
LandingPad->getParent()->getUniquePredecessor(); |
| 5543 |
|
5543 |
|
| 5544 |
// Landingpad relocates should have only one predecessor with invoke |
5544 |
// Landingpad relocates should have only one predecessor with invoke |
| 5545 |
// statepoint terminator |
5545 |
// statepoint terminator |
| 5546 |
Check(InvokeBB, "safepoints should have unique landingpads", |
5546 |
Check(InvokeBB, "safepoints should have unique landingpads", |
| 5547 |
LandingPad->getParent()); |
5547 |
LandingPad->getParent()); |
| 5548 |
Check(InvokeBB->getTerminator(), "safepoint block should be well formed", |
5548 |
Check(InvokeBB->getTerminator(), "safepoint block should be well formed", |
| 5549 |
InvokeBB); |
5549 |
InvokeBB); |
| 5550 |
Check(isa(InvokeBB->getTerminator()), |
5550 |
Check(isa(InvokeBB->getTerminator()), |
| 5551 |
"gc relocate should be linked to a statepoint", InvokeBB); |
5551 |
"gc relocate should be linked to a statepoint", InvokeBB); |
| 5552 |
} else { |
5552 |
} else { |
| 5553 |
// In all other cases relocate should be tied to the statepoint directly. |
5553 |
// In all other cases relocate should be tied to the statepoint directly. |
| 5554 |
// This covers relocates on a normal return path of invoke statepoint and |
5554 |
// This covers relocates on a normal return path of invoke statepoint and |
| 5555 |
// relocates of a call statepoint. |
5555 |
// relocates of a call statepoint. |
| 5556 |
auto *Token = Call.getArgOperand(0); |
5556 |
auto *Token = Call.getArgOperand(0); |
| 5557 |
Check(isa(Token) || isa(Token), |
5557 |
Check(isa(Token) || isa(Token), |
| 5558 |
"gc relocate is incorrectly tied to the statepoint", Call, Token); |
5558 |
"gc relocate is incorrectly tied to the statepoint", Call, Token); |
| 5559 |
} |
5559 |
} |
| 5560 |
|
5560 |
|
| 5561 |
// Verify rest of the relocate arguments. |
5561 |
// Verify rest of the relocate arguments. |
| 5562 |
const Value &StatepointCall = *cast(Call).getStatepoint(); |
5562 |
const Value &StatepointCall = *cast(Call).getStatepoint(); |
| 5563 |
|
5563 |
|
| 5564 |
// Both the base and derived must be piped through the safepoint. |
5564 |
// Both the base and derived must be piped through the safepoint. |
| 5565 |
Value *Base = Call.getArgOperand(1); |
5565 |
Value *Base = Call.getArgOperand(1); |
| 5566 |
Check(isa(Base), |
5566 |
Check(isa(Base), |
| 5567 |
"gc.relocate operand #2 must be integer offset", Call); |
5567 |
"gc.relocate operand #2 must be integer offset", Call); |
| 5568 |
|
5568 |
|
| 5569 |
Value *Derived = Call.getArgOperand(2); |
5569 |
Value *Derived = Call.getArgOperand(2); |
| 5570 |
Check(isa(Derived), |
5570 |
Check(isa(Derived), |
| 5571 |
"gc.relocate operand #3 must be integer offset", Call); |
5571 |
"gc.relocate operand #3 must be integer offset", Call); |
| 5572 |
|
5572 |
|
| 5573 |
const uint64_t BaseIndex = cast(Base)->getZExtValue(); |
5573 |
const uint64_t BaseIndex = cast(Base)->getZExtValue(); |
| 5574 |
const uint64_t DerivedIndex = cast(Derived)->getZExtValue(); |
5574 |
const uint64_t DerivedIndex = cast(Derived)->getZExtValue(); |
| 5575 |
|
5575 |
|
| 5576 |
// Check the bounds |
5576 |
// Check the bounds |
| 5577 |
if (isa(StatepointCall)) |
5577 |
if (isa(StatepointCall)) |
| 5578 |
break; |
5578 |
break; |
| 5579 |
if (auto Opt = cast(StatepointCall) |
5579 |
if (auto Opt = cast(StatepointCall) |
| 5580 |
.getOperandBundle(LLVMContext::OB_gc_live)) { |
5580 |
.getOperandBundle(LLVMContext::OB_gc_live)) { |
| 5581 |
Check(BaseIndex < Opt->Inputs.size(), |
5581 |
Check(BaseIndex < Opt->Inputs.size(), |
| 5582 |
"gc.relocate: statepoint base index out of bounds", Call); |
5582 |
"gc.relocate: statepoint base index out of bounds", Call); |
| 5583 |
Check(DerivedIndex < Opt->Inputs.size(), |
5583 |
Check(DerivedIndex < Opt->Inputs.size(), |
| 5584 |
"gc.relocate: statepoint derived index out of bounds", Call); |
5584 |
"gc.relocate: statepoint derived index out of bounds", Call); |
| 5585 |
} |
5585 |
} |
| 5586 |
|
5586 |
|
| 5587 |
// Relocated value must be either a pointer type or vector-of-pointer type, |
5587 |
// Relocated value must be either a pointer type or vector-of-pointer type, |
| 5588 |
// but gc_relocate does not need to return the same pointer type as the |
5588 |
// but gc_relocate does not need to return the same pointer type as the |
| 5589 |
// relocated pointer. It can be casted to the correct type later if it's |
5589 |
// relocated pointer. It can be casted to the correct type later if it's |
| 5590 |
// desired. However, they must have the same address space and 'vectorness' |
5590 |
// desired. However, they must have the same address space and 'vectorness' |
| 5591 |
GCRelocateInst &Relocate = cast(Call); |
5591 |
GCRelocateInst &Relocate = cast(Call); |
| 5592 |
auto *ResultType = Call.getType(); |
5592 |
auto *ResultType = Call.getType(); |
| 5593 |
auto *DerivedType = Relocate.getDerivedPtr()->getType(); |
5593 |
auto *DerivedType = Relocate.getDerivedPtr()->getType(); |
| 5594 |
auto *BaseType = Relocate.getBasePtr()->getType(); |
5594 |
auto *BaseType = Relocate.getBasePtr()->getType(); |
| 5595 |
|
5595 |
|
| 5596 |
Check(BaseType->isPtrOrPtrVectorTy(), |
5596 |
Check(BaseType->isPtrOrPtrVectorTy(), |
| 5597 |
"gc.relocate: relocated value must be a pointer", Call); |
5597 |
"gc.relocate: relocated value must be a pointer", Call); |
| 5598 |
Check(DerivedType->isPtrOrPtrVectorTy(), |
5598 |
Check(DerivedType->isPtrOrPtrVectorTy(), |
| 5599 |
"gc.relocate: relocated value must be a pointer", Call); |
5599 |
"gc.relocate: relocated value must be a pointer", Call); |
| 5600 |
|
5600 |
|
| 5601 |
Check(ResultType->isVectorTy() == DerivedType->isVectorTy(), |
5601 |
Check(ResultType->isVectorTy() == DerivedType->isVectorTy(), |
| 5602 |
"gc.relocate: vector relocates to vector and pointer to pointer", |
5602 |
"gc.relocate: vector relocates to vector and pointer to pointer", |
| 5603 |
Call); |
5603 |
Call); |
| 5604 |
Check( |
5604 |
Check( |
| 5605 |
ResultType->getPointerAddressSpace() == |
5605 |
ResultType->getPointerAddressSpace() == |
| 5606 |
DerivedType->getPointerAddressSpace(), |
5606 |
DerivedType->getPointerAddressSpace(), |
| 5607 |
"gc.relocate: relocating a pointer shouldn't change its address space", |
5607 |
"gc.relocate: relocating a pointer shouldn't change its address space", |
| 5608 |
Call); |
5608 |
Call); |
| 5609 |
|
5609 |
|
| 5610 |
auto GC = llvm::getGCStrategy(Relocate.getFunction()->getGC()); |
5610 |
auto GC = llvm::getGCStrategy(Relocate.getFunction()->getGC()); |
| 5611 |
Check(GC, "gc.relocate: calling function must have GCStrategy", |
5611 |
Check(GC, "gc.relocate: calling function must have GCStrategy", |
| 5612 |
Call.getFunction()); |
5612 |
Call.getFunction()); |
| 5613 |
if (GC) { |
5613 |
if (GC) { |
| 5614 |
auto isGCPtr = [&GC](Type *PTy) { |
5614 |
auto isGCPtr = [&GC](Type *PTy) { |
| 5615 |
return GC->isGCManagedPointer(PTy->getScalarType()).value_or(true); |
5615 |
return GC->isGCManagedPointer(PTy->getScalarType()).value_or(true); |
| 5616 |
}; |
5616 |
}; |
| 5617 |
Check(isGCPtr(ResultType), "gc.relocate: must return gc pointer", Call); |
5617 |
Check(isGCPtr(ResultType), "gc.relocate: must return gc pointer", Call); |
| 5618 |
Check(isGCPtr(BaseType), |
5618 |
Check(isGCPtr(BaseType), |
| 5619 |
"gc.relocate: relocated value must be a gc pointer", Call); |
5619 |
"gc.relocate: relocated value must be a gc pointer", Call); |
| 5620 |
Check(isGCPtr(DerivedType), |
5620 |
Check(isGCPtr(DerivedType), |
| 5621 |
"gc.relocate: relocated value must be a gc pointer", Call); |
5621 |
"gc.relocate: relocated value must be a gc pointer", Call); |
| 5622 |
} |
5622 |
} |
| 5623 |
break; |
5623 |
break; |
| 5624 |
} |
5624 |
} |
| 5625 |
case Intrinsic::eh_exceptioncode: |
5625 |
case Intrinsic::eh_exceptioncode: |
| 5626 |
case Intrinsic::eh_exceptionpointer: { |
5626 |
case Intrinsic::eh_exceptionpointer: { |
| 5627 |
Check(isa(Call.getArgOperand(0)), |
5627 |
Check(isa(Call.getArgOperand(0)), |
| 5628 |
"eh.exceptionpointer argument must be a catchpad", Call); |
5628 |
"eh.exceptionpointer argument must be a catchpad", Call); |
| 5629 |
break; |
5629 |
break; |
| 5630 |
} |
5630 |
} |
| 5631 |
case Intrinsic::get_active_lane_mask: { |
5631 |
case Intrinsic::get_active_lane_mask: { |
| 5632 |
Check(Call.getType()->isVectorTy(), |
5632 |
Check(Call.getType()->isVectorTy(), |
| 5633 |
"get_active_lane_mask: must return a " |
5633 |
"get_active_lane_mask: must return a " |
| 5634 |
"vector", |
5634 |
"vector", |
| 5635 |
Call); |
5635 |
Call); |
| 5636 |
auto *ElemTy = Call.getType()->getScalarType(); |
5636 |
auto *ElemTy = Call.getType()->getScalarType(); |
| 5637 |
Check(ElemTy->isIntegerTy(1), |
5637 |
Check(ElemTy->isIntegerTy(1), |
| 5638 |
"get_active_lane_mask: element type is not " |
5638 |
"get_active_lane_mask: element type is not " |
| 5639 |
"i1", |
5639 |
"i1", |
| 5640 |
Call); |
5640 |
Call); |
| 5641 |
break; |
5641 |
break; |
| 5642 |
} |
5642 |
} |
| 5643 |
case Intrinsic::experimental_get_vector_length: { |
5643 |
case Intrinsic::experimental_get_vector_length: { |
| 5644 |
ConstantInt *VF = cast(Call.getArgOperand(1)); |
5644 |
ConstantInt *VF = cast(Call.getArgOperand(1)); |
| 5645 |
Check(!VF->isNegative() && !VF->isZero(), |
5645 |
Check(!VF->isNegative() && !VF->isZero(), |
| 5646 |
"get_vector_length: VF must be positive", Call); |
5646 |
"get_vector_length: VF must be positive", Call); |
| 5647 |
break; |
5647 |
break; |
| 5648 |
} |
5648 |
} |
| 5649 |
case Intrinsic::masked_load: { |
5649 |
case Intrinsic::masked_load: { |
| 5650 |
Check(Call.getType()->isVectorTy(), "masked_load: must return a vector", |
5650 |
Check(Call.getType()->isVectorTy(), "masked_load: must return a vector", |
| 5651 |
Call); |
5651 |
Call); |
| 5652 |
|
5652 |
|
| 5653 |
ConstantInt *Alignment = cast(Call.getArgOperand(1)); |
5653 |
ConstantInt *Alignment = cast(Call.getArgOperand(1)); |
| 5654 |
Value *Mask = Call.getArgOperand(2); |
5654 |
Value *Mask = Call.getArgOperand(2); |
| 5655 |
Value *PassThru = Call.getArgOperand(3); |
5655 |
Value *PassThru = Call.getArgOperand(3); |
| 5656 |
Check(Mask->getType()->isVectorTy(), "masked_load: mask must be vector", |
5656 |
Check(Mask->getType()->isVectorTy(), "masked_load: mask must be vector", |
| 5657 |
Call); |
5657 |
Call); |
| 5658 |
Check(Alignment->getValue().isPowerOf2(), |
5658 |
Check(Alignment->getValue().isPowerOf2(), |
| 5659 |
"masked_load: alignment must be a power of 2", Call); |
5659 |
"masked_load: alignment must be a power of 2", Call); |
| 5660 |
Check(PassThru->getType() == Call.getType(), |
5660 |
Check(PassThru->getType() == Call.getType(), |
| 5661 |
"masked_load: pass through and return type must match", Call); |
5661 |
"masked_load: pass through and return type must match", Call); |
| 5662 |
Check(cast(Mask->getType())->getElementCount() == |
5662 |
Check(cast(Mask->getType())->getElementCount() == |
| 5663 |
cast(Call.getType())->getElementCount(), |
5663 |
cast(Call.getType())->getElementCount(), |
| 5664 |
"masked_load: vector mask must be same length as return", Call); |
5664 |
"masked_load: vector mask must be same length as return", Call); |
| 5665 |
break; |
5665 |
break; |
| 5666 |
} |
5666 |
} |
| 5667 |
case Intrinsic::masked_store: { |
5667 |
case Intrinsic::masked_store: { |
| 5668 |
Value *Val = Call.getArgOperand(0); |
5668 |
Value *Val = Call.getArgOperand(0); |
| 5669 |
ConstantInt *Alignment = cast(Call.getArgOperand(2)); |
5669 |
ConstantInt *Alignment = cast(Call.getArgOperand(2)); |
| 5670 |
Value *Mask = Call.getArgOperand(3); |
5670 |
Value *Mask = Call.getArgOperand(3); |
| 5671 |
Check(Mask->getType()->isVectorTy(), "masked_store: mask must be vector", |
5671 |
Check(Mask->getType()->isVectorTy(), "masked_store: mask must be vector", |
| 5672 |
Call); |
5672 |
Call); |
| 5673 |
Check(Alignment->getValue().isPowerOf2(), |
5673 |
Check(Alignment->getValue().isPowerOf2(), |
| 5674 |
"masked_store: alignment must be a power of 2", Call); |
5674 |
"masked_store: alignment must be a power of 2", Call); |
| 5675 |
Check(cast(Mask->getType())->getElementCount() == |
5675 |
Check(cast(Mask->getType())->getElementCount() == |
| 5676 |
cast(Val->getType())->getElementCount(), |
5676 |
cast(Val->getType())->getElementCount(), |
| 5677 |
"masked_store: vector mask must be same length as value", Call); |
5677 |
"masked_store: vector mask must be same length as value", Call); |
| 5678 |
break; |
5678 |
break; |
| 5679 |
} |
5679 |
} |
| 5680 |
|
5680 |
|
| 5681 |
case Intrinsic::masked_gather: { |
5681 |
case Intrinsic::masked_gather: { |
| 5682 |
const APInt &Alignment = |
5682 |
const APInt &Alignment = |
| 5683 |
cast(Call.getArgOperand(1))->getValue(); |
5683 |
cast(Call.getArgOperand(1))->getValue(); |
| 5684 |
Check(Alignment.isZero() || Alignment.isPowerOf2(), |
5684 |
Check(Alignment.isZero() || Alignment.isPowerOf2(), |
| 5685 |
"masked_gather: alignment must be 0 or a power of 2", Call); |
5685 |
"masked_gather: alignment must be 0 or a power of 2", Call); |
| 5686 |
break; |
5686 |
break; |
| 5687 |
} |
5687 |
} |
| 5688 |
case Intrinsic::masked_scatter: { |
5688 |
case Intrinsic::masked_scatter: { |
| 5689 |
const APInt &Alignment = |
5689 |
const APInt &Alignment = |
| 5690 |
cast(Call.getArgOperand(2))->getValue(); |
5690 |
cast(Call.getArgOperand(2))->getValue(); |
| 5691 |
Check(Alignment.isZero() || Alignment.isPowerOf2(), |
5691 |
Check(Alignment.isZero() || Alignment.isPowerOf2(), |
| 5692 |
"masked_scatter: alignment must be 0 or a power of 2", Call); |
5692 |
"masked_scatter: alignment must be 0 or a power of 2", Call); |
| 5693 |
break; |
5693 |
break; |
| 5694 |
} |
5694 |
} |
| 5695 |
|
5695 |
|
| 5696 |
case Intrinsic::experimental_guard: { |
5696 |
case Intrinsic::experimental_guard: { |
| 5697 |
Check(isa(Call), "experimental_guard cannot be invoked", Call); |
5697 |
Check(isa(Call), "experimental_guard cannot be invoked", Call); |
| 5698 |
Check(Call.countOperandBundlesOfType(LLVMContext::OB_deopt) == 1, |
5698 |
Check(Call.countOperandBundlesOfType(LLVMContext::OB_deopt) == 1, |
| 5699 |
"experimental_guard must have exactly one " |
5699 |
"experimental_guard must have exactly one " |
| 5700 |
"\"deopt\" operand bundle"); |
5700 |
"\"deopt\" operand bundle"); |
| 5701 |
break; |
5701 |
break; |
| 5702 |
} |
5702 |
} |
| 5703 |
|
5703 |
|
| 5704 |
case Intrinsic::experimental_deoptimize: { |
5704 |
case Intrinsic::experimental_deoptimize: { |
| 5705 |
Check(isa(Call), "experimental_deoptimize cannot be invoked", |
5705 |
Check(isa(Call), "experimental_deoptimize cannot be invoked", |
| 5706 |
Call); |
5706 |
Call); |
| 5707 |
Check(Call.countOperandBundlesOfType(LLVMContext::OB_deopt) == 1, |
5707 |
Check(Call.countOperandBundlesOfType(LLVMContext::OB_deopt) == 1, |
| 5708 |
"experimental_deoptimize must have exactly one " |
5708 |
"experimental_deoptimize must have exactly one " |
| 5709 |
"\"deopt\" operand bundle"); |
5709 |
"\"deopt\" operand bundle"); |
| 5710 |
Check(Call.getType() == Call.getFunction()->getReturnType(), |
5710 |
Check(Call.getType() == Call.getFunction()->getReturnType(), |
| 5711 |
"experimental_deoptimize return type must match caller return type"); |
5711 |
"experimental_deoptimize return type must match caller return type"); |
| 5712 |
|
5712 |
|
| 5713 |
if (isa(Call)) { |
5713 |
if (isa(Call)) { |
| 5714 |
auto *RI = dyn_cast(Call.getNextNode()); |
5714 |
auto *RI = dyn_cast(Call.getNextNode()); |
| 5715 |
Check(RI, |
5715 |
Check(RI, |
| 5716 |
"calls to experimental_deoptimize must be followed by a return"); |
5716 |
"calls to experimental_deoptimize must be followed by a return"); |
| 5717 |
|
5717 |
|
| 5718 |
if (!Call.getType()->isVoidTy() && RI) |
5718 |
if (!Call.getType()->isVoidTy() && RI) |
| 5719 |
Check(RI->getReturnValue() == &Call, |
5719 |
Check(RI->getReturnValue() == &Call, |
| 5720 |
"calls to experimental_deoptimize must be followed by a return " |
5720 |
"calls to experimental_deoptimize must be followed by a return " |
| 5721 |
"of the value computed by experimental_deoptimize"); |
5721 |
"of the value computed by experimental_deoptimize"); |
| 5722 |
} |
5722 |
} |
| 5723 |
|
5723 |
|
| 5724 |
break; |
5724 |
break; |
| 5725 |
} |
5725 |
} |
| 5726 |
case Intrinsic::vector_reduce_and: |
5726 |
case Intrinsic::vector_reduce_and: |
| 5727 |
case Intrinsic::vector_reduce_or: |
5727 |
case Intrinsic::vector_reduce_or: |
| 5728 |
case Intrinsic::vector_reduce_xor: |
5728 |
case Intrinsic::vector_reduce_xor: |
| 5729 |
case Intrinsic::vector_reduce_add: |
5729 |
case Intrinsic::vector_reduce_add: |
| 5730 |
case Intrinsic::vector_reduce_mul: |
5730 |
case Intrinsic::vector_reduce_mul: |
| 5731 |
case Intrinsic::vector_reduce_smax: |
5731 |
case Intrinsic::vector_reduce_smax: |
| 5732 |
case Intrinsic::vector_reduce_smin: |
5732 |
case Intrinsic::vector_reduce_smin: |
| 5733 |
case Intrinsic::vector_reduce_umax: |
5733 |
case Intrinsic::vector_reduce_umax: |
| 5734 |
case Intrinsic::vector_reduce_umin: { |
5734 |
case Intrinsic::vector_reduce_umin: { |
| 5735 |
Type *ArgTy = Call.getArgOperand(0)->getType(); |
5735 |
Type *ArgTy = Call.getArgOperand(0)->getType(); |
| 5736 |
Check(ArgTy->isIntOrIntVectorTy() && ArgTy->isVectorTy(), |
5736 |
Check(ArgTy->isIntOrIntVectorTy() && ArgTy->isVectorTy(), |
| 5737 |
"Intrinsic has incorrect argument type!"); |
5737 |
"Intrinsic has incorrect argument type!"); |
| 5738 |
break; |
5738 |
break; |
| 5739 |
} |
5739 |
} |
| 5740 |
case Intrinsic::vector_reduce_fmax: |
5740 |
case Intrinsic::vector_reduce_fmax: |
| 5741 |
case Intrinsic::vector_reduce_fmin: { |
5741 |
case Intrinsic::vector_reduce_fmin: { |
| 5742 |
Type *ArgTy = Call.getArgOperand(0)->getType(); |
5742 |
Type *ArgTy = Call.getArgOperand(0)->getType(); |
| 5743 |
Check(ArgTy->isFPOrFPVectorTy() && ArgTy->isVectorTy(), |
5743 |
Check(ArgTy->isFPOrFPVectorTy() && ArgTy->isVectorTy(), |
| 5744 |
"Intrinsic has incorrect argument type!"); |
5744 |
"Intrinsic has incorrect argument type!"); |
| 5745 |
break; |
5745 |
break; |
| 5746 |
} |
5746 |
} |
| 5747 |
case Intrinsic::vector_reduce_fadd: |
5747 |
case Intrinsic::vector_reduce_fadd: |
| 5748 |
case Intrinsic::vector_reduce_fmul: { |
5748 |
case Intrinsic::vector_reduce_fmul: { |
| 5749 |
// Unlike the other reductions, the first argument is a start value. The |
5749 |
// Unlike the other reductions, the first argument is a start value. The |
| 5750 |
// second argument is the vector to be reduced. |
5750 |
// second argument is the vector to be reduced. |
| 5751 |
Type *ArgTy = Call.getArgOperand(1)->getType(); |
5751 |
Type *ArgTy = Call.getArgOperand(1)->getType(); |
| 5752 |
Check(ArgTy->isFPOrFPVectorTy() && ArgTy->isVectorTy(), |
5752 |
Check(ArgTy->isFPOrFPVectorTy() && ArgTy->isVectorTy(), |
| 5753 |
"Intrinsic has incorrect argument type!"); |
5753 |
"Intrinsic has incorrect argument type!"); |
| 5754 |
break; |
5754 |
break; |
| 5755 |
} |
5755 |
} |
| 5756 |
case Intrinsic::smul_fix: |
5756 |
case Intrinsic::smul_fix: |
| 5757 |
case Intrinsic::smul_fix_sat: |
5757 |
case Intrinsic::smul_fix_sat: |
| 5758 |
case Intrinsic::umul_fix: |
5758 |
case Intrinsic::umul_fix: |
| 5759 |
case Intrinsic::umul_fix_sat: |
5759 |
case Intrinsic::umul_fix_sat: |
| 5760 |
case Intrinsic::sdiv_fix: |
5760 |
case Intrinsic::sdiv_fix: |
| 5761 |
case Intrinsic::sdiv_fix_sat: |
5761 |
case Intrinsic::sdiv_fix_sat: |
| 5762 |
case Intrinsic::udiv_fix: |
5762 |
case Intrinsic::udiv_fix: |
| 5763 |
case Intrinsic::udiv_fix_sat: { |
5763 |
case Intrinsic::udiv_fix_sat: { |
| 5764 |
Value *Op1 = Call.getArgOperand(0); |
5764 |
Value *Op1 = Call.getArgOperand(0); |
| 5765 |
Value *Op2 = Call.getArgOperand(1); |
5765 |
Value *Op2 = Call.getArgOperand(1); |
| 5766 |
Check(Op1->getType()->isIntOrIntVectorTy(), |
5766 |
Check(Op1->getType()->isIntOrIntVectorTy(), |
| 5767 |
"first operand of [us][mul|div]_fix[_sat] must be an int type or " |
5767 |
"first operand of [us][mul|div]_fix[_sat] must be an int type or " |
| 5768 |
"vector of ints"); |
5768 |
"vector of ints"); |
| 5769 |
Check(Op2->getType()->isIntOrIntVectorTy(), |
5769 |
Check(Op2->getType()->isIntOrIntVectorTy(), |
| 5770 |
"second operand of [us][mul|div]_fix[_sat] must be an int type or " |
5770 |
"second operand of [us][mul|div]_fix[_sat] must be an int type or " |
| 5771 |
"vector of ints"); |
5771 |
"vector of ints"); |
| 5772 |
|
5772 |
|
| 5773 |
auto *Op3 = cast(Call.getArgOperand(2)); |
5773 |
auto *Op3 = cast(Call.getArgOperand(2)); |
| 5774 |
Check(Op3->getType()->getBitWidth() <= 32, |
5774 |
Check(Op3->getType()->getBitWidth() <= 32, |
| 5775 |
"third argument of [us][mul|div]_fix[_sat] must fit within 32 bits"); |
5775 |
"third argument of [us][mul|div]_fix[_sat] must fit within 32 bits"); |
| 5776 |
|
5776 |
|
| 5777 |
if (ID == Intrinsic::smul_fix || ID == Intrinsic::smul_fix_sat || |
5777 |
if (ID == Intrinsic::smul_fix || ID == Intrinsic::smul_fix_sat || |
| 5778 |
ID == Intrinsic::sdiv_fix || ID == Intrinsic::sdiv_fix_sat) { |
5778 |
ID == Intrinsic::sdiv_fix || ID == Intrinsic::sdiv_fix_sat) { |
| 5779 |
Check(Op3->getZExtValue() < Op1->getType()->getScalarSizeInBits(), |
5779 |
Check(Op3->getZExtValue() < Op1->getType()->getScalarSizeInBits(), |
| 5780 |
"the scale of s[mul|div]_fix[_sat] must be less than the width of " |
5780 |
"the scale of s[mul|div]_fix[_sat] must be less than the width of " |
| 5781 |
"the operands"); |
5781 |
"the operands"); |
| 5782 |
} else { |
5782 |
} else { |
| 5783 |
Check(Op3->getZExtValue() <= Op1->getType()->getScalarSizeInBits(), |
5783 |
Check(Op3->getZExtValue() <= Op1->getType()->getScalarSizeInBits(), |
| 5784 |
"the scale of u[mul|div]_fix[_sat] must be less than or equal " |
5784 |
"the scale of u[mul|div]_fix[_sat] must be less than or equal " |
| 5785 |
"to the width of the operands"); |
5785 |
"to the width of the operands"); |
| 5786 |
} |
5786 |
} |
| 5787 |
break; |
5787 |
break; |
| 5788 |
} |
5788 |
} |
| 5789 |
case Intrinsic::lround: |
5789 |
case Intrinsic::lround: |
| 5790 |
case Intrinsic::llround: |
5790 |
case Intrinsic::llround: |
| 5791 |
case Intrinsic::lrint: |
5791 |
case Intrinsic::lrint: |
| 5792 |
case Intrinsic::llrint: { |
5792 |
case Intrinsic::llrint: { |
| 5793 |
Type *ValTy = Call.getArgOperand(0)->getType(); |
5793 |
Type *ValTy = Call.getArgOperand(0)->getType(); |
| 5794 |
Type *ResultTy = Call.getType(); |
5794 |
Type *ResultTy = Call.getType(); |
| 5795 |
Check(!ValTy->isVectorTy() && !ResultTy->isVectorTy(), |
5795 |
Check(!ValTy->isVectorTy() && !ResultTy->isVectorTy(), |
| 5796 |
"Intrinsic does not support vectors", &Call); |
5796 |
"Intrinsic does not support vectors", &Call); |
| 5797 |
break; |
5797 |
break; |
| 5798 |
} |
5798 |
} |
| 5799 |
case Intrinsic::bswap: { |
5799 |
case Intrinsic::bswap: { |
| 5800 |
Type *Ty = Call.getType(); |
5800 |
Type *Ty = Call.getType(); |
| 5801 |
unsigned Size = Ty->getScalarSizeInBits(); |
5801 |
unsigned Size = Ty->getScalarSizeInBits(); |
| 5802 |
Check(Size % 16 == 0, "bswap must be an even number of bytes", &Call); |
5802 |
Check(Size % 16 == 0, "bswap must be an even number of bytes", &Call); |
| 5803 |
break; |
5803 |
break; |
| 5804 |
} |
5804 |
} |
| 5805 |
case Intrinsic::invariant_start: { |
5805 |
case Intrinsic::invariant_start: { |
| 5806 |
ConstantInt *InvariantSize = dyn_cast(Call.getArgOperand(0)); |
5806 |
ConstantInt *InvariantSize = dyn_cast(Call.getArgOperand(0)); |
| 5807 |
Check(InvariantSize && |
5807 |
Check(InvariantSize && |
| 5808 |
(!InvariantSize->isNegative() || InvariantSize->isMinusOne()), |
5808 |
(!InvariantSize->isNegative() || InvariantSize->isMinusOne()), |
| 5809 |
"invariant_start parameter must be -1, 0 or a positive number", |
5809 |
"invariant_start parameter must be -1, 0 or a positive number", |
| 5810 |
&Call); |
5810 |
&Call); |
| 5811 |
break; |
5811 |
break; |
| 5812 |
} |
5812 |
} |
| 5813 |
case Intrinsic::matrix_multiply: |
5813 |
case Intrinsic::matrix_multiply: |
| 5814 |
case Intrinsic::matrix_transpose: |
5814 |
case Intrinsic::matrix_transpose: |
| 5815 |
case Intrinsic::matrix_column_major_load: |
5815 |
case Intrinsic::matrix_column_major_load: |
| 5816 |
case Intrinsic::matrix_column_major_store: { |
5816 |
case Intrinsic::matrix_column_major_store: { |
| 5817 |
Function *IF = Call.getCalledFunction(); |
5817 |
Function *IF = Call.getCalledFunction(); |
| 5818 |
ConstantInt *Stride = nullptr; |
5818 |
ConstantInt *Stride = nullptr; |
| 5819 |
ConstantInt *NumRows; |
5819 |
ConstantInt *NumRows; |
| 5820 |
ConstantInt *NumColumns; |
5820 |
ConstantInt *NumColumns; |
| 5821 |
VectorType *ResultTy; |
5821 |
VectorType *ResultTy; |
| 5822 |
Type *Op0ElemTy = nullptr; |
5822 |
Type *Op0ElemTy = nullptr; |
| 5823 |
Type *Op1ElemTy = nullptr; |
5823 |
Type *Op1ElemTy = nullptr; |
| 5824 |
switch (ID) { |
5824 |
switch (ID) { |
| 5825 |
case Intrinsic::matrix_multiply: { |
5825 |
case Intrinsic::matrix_multiply: { |
| 5826 |
NumRows = cast(Call.getArgOperand(2)); |
5826 |
NumRows = cast(Call.getArgOperand(2)); |
| 5827 |
ConstantInt *N = cast(Call.getArgOperand(3)); |
5827 |
ConstantInt *N = cast(Call.getArgOperand(3)); |
| 5828 |
NumColumns = cast(Call.getArgOperand(4)); |
5828 |
NumColumns = cast(Call.getArgOperand(4)); |
| 5829 |
Check(cast(Call.getArgOperand(0)->getType()) |
5829 |
Check(cast(Call.getArgOperand(0)->getType()) |
| 5830 |
->getNumElements() == |
5830 |
->getNumElements() == |
| 5831 |
NumRows->getZExtValue() * N->getZExtValue(), |
5831 |
NumRows->getZExtValue() * N->getZExtValue(), |
| 5832 |
"First argument of a matrix operation does not match specified " |
5832 |
"First argument of a matrix operation does not match specified " |
| 5833 |
"shape!"); |
5833 |
"shape!"); |
| 5834 |
Check(cast(Call.getArgOperand(1)->getType()) |
5834 |
Check(cast(Call.getArgOperand(1)->getType()) |
| 5835 |
->getNumElements() == |
5835 |
->getNumElements() == |
| 5836 |
N->getZExtValue() * NumColumns->getZExtValue(), |
5836 |
N->getZExtValue() * NumColumns->getZExtValue(), |
| 5837 |
"Second argument of a matrix operation does not match specified " |
5837 |
"Second argument of a matrix operation does not match specified " |
| 5838 |
"shape!"); |
5838 |
"shape!"); |
| 5839 |
|
5839 |
|
| 5840 |
ResultTy = cast(Call.getType()); |
5840 |
ResultTy = cast(Call.getType()); |
| 5841 |
Op0ElemTy = |
5841 |
Op0ElemTy = |
| 5842 |
cast(Call.getArgOperand(0)->getType())->getElementType(); |
5842 |
cast(Call.getArgOperand(0)->getType())->getElementType(); |
| 5843 |
Op1ElemTy = |
5843 |
Op1ElemTy = |
| 5844 |
cast(Call.getArgOperand(1)->getType())->getElementType(); |
5844 |
cast(Call.getArgOperand(1)->getType())->getElementType(); |
| 5845 |
break; |
5845 |
break; |
| 5846 |
} |
5846 |
} |
| 5847 |
case Intrinsic::matrix_transpose: |
5847 |
case Intrinsic::matrix_transpose: |
| 5848 |
NumRows = cast(Call.getArgOperand(1)); |
5848 |
NumRows = cast(Call.getArgOperand(1)); |
| 5849 |
NumColumns = cast(Call.getArgOperand(2)); |
5849 |
NumColumns = cast(Call.getArgOperand(2)); |
| 5850 |
ResultTy = cast(Call.getType()); |
5850 |
ResultTy = cast(Call.getType()); |
| 5851 |
Op0ElemTy = |
5851 |
Op0ElemTy = |
| 5852 |
cast(Call.getArgOperand(0)->getType())->getElementType(); |
5852 |
cast(Call.getArgOperand(0)->getType())->getElementType(); |
| 5853 |
break; |
5853 |
break; |
| 5854 |
case Intrinsic::matrix_column_major_load: { |
5854 |
case Intrinsic::matrix_column_major_load: { |
| 5855 |
Stride = dyn_cast(Call.getArgOperand(1)); |
5855 |
Stride = dyn_cast(Call.getArgOperand(1)); |
| 5856 |
NumRows = cast(Call.getArgOperand(3)); |
5856 |
NumRows = cast(Call.getArgOperand(3)); |
| 5857 |
NumColumns = cast(Call.getArgOperand(4)); |
5857 |
NumColumns = cast(Call.getArgOperand(4)); |
| 5858 |
ResultTy = cast(Call.getType()); |
5858 |
ResultTy = cast(Call.getType()); |
| 5859 |
break; |
5859 |
break; |
| 5860 |
} |
5860 |
} |
| 5861 |
case Intrinsic::matrix_column_major_store: { |
5861 |
case Intrinsic::matrix_column_major_store: { |
| 5862 |
Stride = dyn_cast(Call.getArgOperand(2)); |
5862 |
Stride = dyn_cast(Call.getArgOperand(2)); |
| 5863 |
NumRows = cast(Call.getArgOperand(4)); |
5863 |
NumRows = cast(Call.getArgOperand(4)); |
| 5864 |
NumColumns = cast(Call.getArgOperand(5)); |
5864 |
NumColumns = cast(Call.getArgOperand(5)); |
| 5865 |
ResultTy = cast(Call.getArgOperand(0)->getType()); |
5865 |
ResultTy = cast(Call.getArgOperand(0)->getType()); |
| 5866 |
Op0ElemTy = |
5866 |
Op0ElemTy = |
| 5867 |
cast(Call.getArgOperand(0)->getType())->getElementType(); |
5867 |
cast(Call.getArgOperand(0)->getType())->getElementType(); |
| 5868 |
break; |
5868 |
break; |
| 5869 |
} |
5869 |
} |
| 5870 |
default: |
5870 |
default: |
| 5871 |
llvm_unreachable("unexpected intrinsic"); |
5871 |
llvm_unreachable("unexpected intrinsic"); |
| 5872 |
} |
5872 |
} |
| 5873 |
|
5873 |
|
| 5874 |
Check(ResultTy->getElementType()->isIntegerTy() || |
5874 |
Check(ResultTy->getElementType()->isIntegerTy() || |
| 5875 |
ResultTy->getElementType()->isFloatingPointTy(), |
5875 |
ResultTy->getElementType()->isFloatingPointTy(), |
| 5876 |
"Result type must be an integer or floating-point type!", IF); |
5876 |
"Result type must be an integer or floating-point type!", IF); |
| 5877 |
|
5877 |
|
| 5878 |
if (Op0ElemTy) |
5878 |
if (Op0ElemTy) |
| 5879 |
Check(ResultTy->getElementType() == Op0ElemTy, |
5879 |
Check(ResultTy->getElementType() == Op0ElemTy, |
| 5880 |
"Vector element type mismatch of the result and first operand " |
5880 |
"Vector element type mismatch of the result and first operand " |
| 5881 |
"vector!", |
5881 |
"vector!", |
| 5882 |
IF); |
5882 |
IF); |
| 5883 |
|
5883 |
|
| 5884 |
if (Op1ElemTy) |
5884 |
if (Op1ElemTy) |
| 5885 |
Check(ResultTy->getElementType() == Op1ElemTy, |
5885 |
Check(ResultTy->getElementType() == Op1ElemTy, |
| 5886 |
"Vector element type mismatch of the result and second operand " |
5886 |
"Vector element type mismatch of the result and second operand " |
| 5887 |
"vector!", |
5887 |
"vector!", |
| 5888 |
IF); |
5888 |
IF); |
| 5889 |
|
5889 |
|
| 5890 |
Check(cast(ResultTy)->getNumElements() == |
5890 |
Check(cast(ResultTy)->getNumElements() == |
| 5891 |
NumRows->getZExtValue() * NumColumns->getZExtValue(), |
5891 |
NumRows->getZExtValue() * NumColumns->getZExtValue(), |
| 5892 |
"Result of a matrix operation does not fit in the returned vector!"); |
5892 |
"Result of a matrix operation does not fit in the returned vector!"); |
| 5893 |
|
5893 |
|
| 5894 |
if (Stride) |
5894 |
if (Stride) |
| 5895 |
Check(Stride->getZExtValue() >= NumRows->getZExtValue(), |
5895 |
Check(Stride->getZExtValue() >= NumRows->getZExtValue(), |
| 5896 |
"Stride must be greater or equal than the number of rows!", IF); |
5896 |
"Stride must be greater or equal than the number of rows!", IF); |
| 5897 |
|
5897 |
|
| 5898 |
break; |
5898 |
break; |
| 5899 |
} |
5899 |
} |
| 5900 |
case Intrinsic::experimental_vector_splice: { |
5900 |
case Intrinsic::experimental_vector_splice: { |
| 5901 |
VectorType *VecTy = cast(Call.getType()); |
5901 |
VectorType *VecTy = cast(Call.getType()); |
| 5902 |
int64_t Idx = cast(Call.getArgOperand(2))->getSExtValue(); |
5902 |
int64_t Idx = cast(Call.getArgOperand(2))->getSExtValue(); |
| 5903 |
int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue(); |
5903 |
int64_t KnownMinNumElements = VecTy->getElementCount().getKnownMinValue(); |
| 5904 |
if (Call.getParent() && Call.getParent()->getParent()) { |
5904 |
if (Call.getParent() && Call.getParent()->getParent()) { |
| 5905 |
AttributeList Attrs = Call.getParent()->getParent()->getAttributes(); |
5905 |
AttributeList Attrs = Call.getParent()->getParent()->getAttributes(); |
| 5906 |
if (Attrs.hasFnAttr(Attribute::VScaleRange)) |
5906 |
if (Attrs.hasFnAttr(Attribute::VScaleRange)) |
| 5907 |
KnownMinNumElements *= Attrs.getFnAttrs().getVScaleRangeMin(); |
5907 |
KnownMinNumElements *= Attrs.getFnAttrs().getVScaleRangeMin(); |
| 5908 |
} |
5908 |
} |
| 5909 |
Check((Idx < 0 && std::abs(Idx) <= KnownMinNumElements) || |
5909 |
Check((Idx < 0 && std::abs(Idx) <= KnownMinNumElements) || |
| 5910 |
(Idx >= 0 && Idx < KnownMinNumElements), |
5910 |
(Idx >= 0 && Idx < KnownMinNumElements), |
| 5911 |
"The splice index exceeds the range [-VL, VL-1] where VL is the " |
5911 |
"The splice index exceeds the range [-VL, VL-1] where VL is the " |
| 5912 |
"known minimum number of elements in the vector. For scalable " |
5912 |
"known minimum number of elements in the vector. For scalable " |
| 5913 |
"vectors the minimum number of elements is determined from " |
5913 |
"vectors the minimum number of elements is determined from " |
| 5914 |
"vscale_range.", |
5914 |
"vscale_range.", |
| 5915 |
&Call); |
5915 |
&Call); |
| 5916 |
break; |
5916 |
break; |
| 5917 |
} |
5917 |
} |
| 5918 |
case Intrinsic::experimental_stepvector: { |
5918 |
case Intrinsic::experimental_stepvector: { |
| 5919 |
VectorType *VecTy = dyn_cast(Call.getType()); |
5919 |
VectorType *VecTy = dyn_cast(Call.getType()); |
| 5920 |
Check(VecTy && VecTy->getScalarType()->isIntegerTy() && |
5920 |
Check(VecTy && VecTy->getScalarType()->isIntegerTy() && |
| 5921 |
VecTy->getScalarSizeInBits() >= 8, |
5921 |
VecTy->getScalarSizeInBits() >= 8, |
| 5922 |
"experimental_stepvector only supported for vectors of integers " |
5922 |
"experimental_stepvector only supported for vectors of integers " |
| 5923 |
"with a bitwidth of at least 8.", |
5923 |
"with a bitwidth of at least 8.", |
| 5924 |
&Call); |
5924 |
&Call); |
| 5925 |
break; |
5925 |
break; |
| 5926 |
} |
5926 |
} |
| 5927 |
case Intrinsic::vector_insert: { |
5927 |
case Intrinsic::vector_insert: { |
| 5928 |
Value *Vec = Call.getArgOperand(0); |
5928 |
Value *Vec = Call.getArgOperand(0); |
| 5929 |
Value *SubVec = Call.getArgOperand(1); |
5929 |
Value *SubVec = Call.getArgOperand(1); |
| 5930 |
Value *Idx = Call.getArgOperand(2); |
5930 |
Value *Idx = Call.getArgOperand(2); |
| 5931 |
unsigned IdxN = cast(Idx)->getZExtValue(); |
5931 |
unsigned IdxN = cast(Idx)->getZExtValue(); |
| 5932 |
|
5932 |
|
| 5933 |
VectorType *VecTy = cast(Vec->getType()); |
5933 |
VectorType *VecTy = cast(Vec->getType()); |
| 5934 |
VectorType *SubVecTy = cast(SubVec->getType()); |
5934 |
VectorType *SubVecTy = cast(SubVec->getType()); |
| 5935 |
|
5935 |
|
| 5936 |
ElementCount VecEC = VecTy->getElementCount(); |
5936 |
ElementCount VecEC = VecTy->getElementCount(); |
| 5937 |
ElementCount SubVecEC = SubVecTy->getElementCount(); |
5937 |
ElementCount SubVecEC = SubVecTy->getElementCount(); |
| 5938 |
Check(VecTy->getElementType() == SubVecTy->getElementType(), |
5938 |
Check(VecTy->getElementType() == SubVecTy->getElementType(), |
| 5939 |
"vector_insert parameters must have the same element " |
5939 |
"vector_insert parameters must have the same element " |
| 5940 |
"type.", |
5940 |
"type.", |
| 5941 |
&Call); |
5941 |
&Call); |
| 5942 |
Check(IdxN % SubVecEC.getKnownMinValue() == 0, |
5942 |
Check(IdxN % SubVecEC.getKnownMinValue() == 0, |
| 5943 |
"vector_insert index must be a constant multiple of " |
5943 |
"vector_insert index must be a constant multiple of " |
| 5944 |
"the subvector's known minimum vector length."); |
5944 |
"the subvector's known minimum vector length."); |
| 5945 |
|
5945 |
|
| 5946 |
// If this insertion is not the 'mixed' case where a fixed vector is |
5946 |
// If this insertion is not the 'mixed' case where a fixed vector is |
| 5947 |
// inserted into a scalable vector, ensure that the insertion of the |
5947 |
// inserted into a scalable vector, ensure that the insertion of the |
| 5948 |
// subvector does not overrun the parent vector. |
5948 |
// subvector does not overrun the parent vector. |
| 5949 |
if (VecEC.isScalable() == SubVecEC.isScalable()) { |
5949 |
if (VecEC.isScalable() == SubVecEC.isScalable()) { |
| 5950 |
Check(IdxN < VecEC.getKnownMinValue() && |
5950 |
Check(IdxN < VecEC.getKnownMinValue() && |
| 5951 |
IdxN + SubVecEC.getKnownMinValue() <= VecEC.getKnownMinValue(), |
5951 |
IdxN + SubVecEC.getKnownMinValue() <= VecEC.getKnownMinValue(), |
| 5952 |
"subvector operand of vector_insert would overrun the " |
5952 |
"subvector operand of vector_insert would overrun the " |
| 5953 |
"vector being inserted into."); |
5953 |
"vector being inserted into."); |
| 5954 |
} |
5954 |
} |
| 5955 |
break; |
5955 |
break; |
| 5956 |
} |
5956 |
} |
| 5957 |
case Intrinsic::vector_extract: { |
5957 |
case Intrinsic::vector_extract: { |
| 5958 |
Value *Vec = Call.getArgOperand(0); |
5958 |
Value *Vec = Call.getArgOperand(0); |
| 5959 |
Value *Idx = Call.getArgOperand(1); |
5959 |
Value *Idx = Call.getArgOperand(1); |
| 5960 |
unsigned IdxN = cast(Idx)->getZExtValue(); |
5960 |
unsigned IdxN = cast(Idx)->getZExtValue(); |
| 5961 |
|
5961 |
|
| 5962 |
VectorType *ResultTy = cast(Call.getType()); |
5962 |
VectorType *ResultTy = cast(Call.getType()); |
| 5963 |
VectorType *VecTy = cast(Vec->getType()); |
5963 |
VectorType *VecTy = cast(Vec->getType()); |
| 5964 |
|
5964 |
|
| 5965 |
ElementCount VecEC = VecTy->getElementCount(); |
5965 |
ElementCount VecEC = VecTy->getElementCount(); |
| 5966 |
ElementCount ResultEC = ResultTy->getElementCount(); |
5966 |
ElementCount ResultEC = ResultTy->getElementCount(); |
| 5967 |
|
5967 |
|
| 5968 |
Check(ResultTy->getElementType() == VecTy->getElementType(), |
5968 |
Check(ResultTy->getElementType() == VecTy->getElementType(), |
| 5969 |
"vector_extract result must have the same element " |
5969 |
"vector_extract result must have the same element " |
| 5970 |
"type as the input vector.", |
5970 |
"type as the input vector.", |
| 5971 |
&Call); |
5971 |
&Call); |
| 5972 |
Check(IdxN % ResultEC.getKnownMinValue() == 0, |
5972 |
Check(IdxN % ResultEC.getKnownMinValue() == 0, |
| 5973 |
"vector_extract index must be a constant multiple of " |
5973 |
"vector_extract index must be a constant multiple of " |
| 5974 |
"the result type's known minimum vector length."); |
5974 |
"the result type's known minimum vector length."); |
| 5975 |
|
5975 |
|
| 5976 |
// If this extraction is not the 'mixed' case where a fixed vector is is |
5976 |
// If this extraction is not the 'mixed' case where a fixed vector is is |
| 5977 |
// extracted from a scalable vector, ensure that the extraction does not |
5977 |
// extracted from a scalable vector, ensure that the extraction does not |
| 5978 |
// overrun the parent vector. |
5978 |
// overrun the parent vector. |
| 5979 |
if (VecEC.isScalable() == ResultEC.isScalable()) { |
5979 |
if (VecEC.isScalable() == ResultEC.isScalable()) { |
| 5980 |
Check(IdxN < VecEC.getKnownMinValue() && |
5980 |
Check(IdxN < VecEC.getKnownMinValue() && |
| 5981 |
IdxN + ResultEC.getKnownMinValue() <= VecEC.getKnownMinValue(), |
5981 |
IdxN + ResultEC.getKnownMinValue() <= VecEC.getKnownMinValue(), |
| 5982 |
"vector_extract would overrun."); |
5982 |
"vector_extract would overrun."); |
| 5983 |
} |
5983 |
} |
| 5984 |
break; |
5984 |
break; |
| 5985 |
} |
5985 |
} |
| 5986 |
case Intrinsic::experimental_noalias_scope_decl: { |
5986 |
case Intrinsic::experimental_noalias_scope_decl: { |
| 5987 |
NoAliasScopeDecls.push_back(cast(&Call)); |
5987 |
NoAliasScopeDecls.push_back(cast(&Call)); |
| 5988 |
break; |
5988 |
break; |
| 5989 |
} |
5989 |
} |
| 5990 |
case Intrinsic::preserve_array_access_index: |
5990 |
case Intrinsic::preserve_array_access_index: |
| 5991 |
case Intrinsic::preserve_struct_access_index: |
5991 |
case Intrinsic::preserve_struct_access_index: |
| 5992 |
case Intrinsic::aarch64_ldaxr: |
5992 |
case Intrinsic::aarch64_ldaxr: |
| 5993 |
case Intrinsic::aarch64_ldxr: |
5993 |
case Intrinsic::aarch64_ldxr: |
| 5994 |
case Intrinsic::arm_ldaex: |
5994 |
case Intrinsic::arm_ldaex: |
| 5995 |
case Intrinsic::arm_ldrex: { |
5995 |
case Intrinsic::arm_ldrex: { |
| 5996 |
Type *ElemTy = Call.getParamElementType(0); |
5996 |
Type *ElemTy = Call.getParamElementType(0); |
| 5997 |
Check(ElemTy, "Intrinsic requires elementtype attribute on first argument.", |
5997 |
Check(ElemTy, "Intrinsic requires elementtype attribute on first argument.", |
| 5998 |
&Call); |
5998 |
&Call); |
| 5999 |
break; |
5999 |
break; |
| 6000 |
} |
6000 |
} |
| 6001 |
case Intrinsic::aarch64_stlxr: |
6001 |
case Intrinsic::aarch64_stlxr: |
| 6002 |
case Intrinsic::aarch64_stxr: |
6002 |
case Intrinsic::aarch64_stxr: |
| 6003 |
case Intrinsic::arm_stlex: |
6003 |
case Intrinsic::arm_stlex: |
| 6004 |
case Intrinsic::arm_strex: { |
6004 |
case Intrinsic::arm_strex: { |
| 6005 |
Type *ElemTy = Call.getAttributes().getParamElementType(1); |
6005 |
Type *ElemTy = Call.getAttributes().getParamElementType(1); |
| 6006 |
Check(ElemTy, |
6006 |
Check(ElemTy, |
| 6007 |
"Intrinsic requires elementtype attribute on second argument.", |
6007 |
"Intrinsic requires elementtype attribute on second argument.", |
| 6008 |
&Call); |
6008 |
&Call); |
| 6009 |
break; |
6009 |
break; |
| 6010 |
} |
6010 |
} |
| 6011 |
case Intrinsic::aarch64_prefetch: { |
6011 |
case Intrinsic::aarch64_prefetch: { |
| 6012 |
Check(cast(Call.getArgOperand(1))->getZExtValue() < 2, |
6012 |
Check(cast(Call.getArgOperand(1))->getZExtValue() < 2, |
| 6013 |
"write argument to llvm.aarch64.prefetch must be 0 or 1", Call); |
6013 |
"write argument to llvm.aarch64.prefetch must be 0 or 1", Call); |
| 6014 |
Check(cast(Call.getArgOperand(2))->getZExtValue() < 4, |
6014 |
Check(cast(Call.getArgOperand(2))->getZExtValue() < 4, |
| 6015 |
"target argument to llvm.aarch64.prefetch must be 0-3", Call); |
6015 |
"target argument to llvm.aarch64.prefetch must be 0-3", Call); |
| 6016 |
Check(cast(Call.getArgOperand(3))->getZExtValue() < 2, |
6016 |
Check(cast(Call.getArgOperand(3))->getZExtValue() < 2, |
| 6017 |
"stream argument to llvm.aarch64.prefetch must be 0 or 1", Call); |
6017 |
"stream argument to llvm.aarch64.prefetch must be 0 or 1", Call); |
| 6018 |
Check(cast(Call.getArgOperand(4))->getZExtValue() < 2, |
6018 |
Check(cast(Call.getArgOperand(4))->getZExtValue() < 2, |
| 6019 |
"isdata argument to llvm.aarch64.prefetch must be 0 or 1", Call); |
6019 |
"isdata argument to llvm.aarch64.prefetch must be 0 or 1", Call); |
| 6020 |
break; |
6020 |
break; |
| 6021 |
} |
6021 |
} |
| 6022 |
case Intrinsic::callbr_landingpad: { |
6022 |
case Intrinsic::callbr_landingpad: { |
| 6023 |
const auto *CBR = dyn_cast(Call.getOperand(0)); |
6023 |
const auto *CBR = dyn_cast(Call.getOperand(0)); |
| 6024 |
Check(CBR, "intrinstic requires callbr operand", &Call); |
6024 |
Check(CBR, "intrinstic requires callbr operand", &Call); |
| 6025 |
if (!CBR) |
6025 |
if (!CBR) |
| 6026 |
break; |
6026 |
break; |
| 6027 |
|
6027 |
|
| 6028 |
const BasicBlock *LandingPadBB = Call.getParent(); |
6028 |
const BasicBlock *LandingPadBB = Call.getParent(); |
| 6029 |
const BasicBlock *PredBB = LandingPadBB->getUniquePredecessor(); |
6029 |
const BasicBlock *PredBB = LandingPadBB->getUniquePredecessor(); |
| 6030 |
if (!PredBB) { |
6030 |
if (!PredBB) { |
| 6031 |
CheckFailed("Intrinsic in block must have 1 unique predecessor", &Call); |
6031 |
CheckFailed("Intrinsic in block must have 1 unique predecessor", &Call); |
| 6032 |
break; |
6032 |
break; |
| 6033 |
} |
6033 |
} |
| 6034 |
if (!isa(PredBB->getTerminator())) { |
6034 |
if (!isa(PredBB->getTerminator())) { |
| 6035 |
CheckFailed("Intrinsic must have corresponding callbr in predecessor", |
6035 |
CheckFailed("Intrinsic must have corresponding callbr in predecessor", |
| 6036 |
&Call); |
6036 |
&Call); |
| 6037 |
break; |
6037 |
break; |
| 6038 |
} |
6038 |
} |
| 6039 |
Check(llvm::any_of(CBR->getIndirectDests(), |
6039 |
Check(llvm::any_of(CBR->getIndirectDests(), |
| 6040 |
[LandingPadBB](const BasicBlock *IndDest) { |
6040 |
[LandingPadBB](const BasicBlock *IndDest) { |
| 6041 |
return IndDest == LandingPadBB; |
6041 |
return IndDest == LandingPadBB; |
| 6042 |
}), |
6042 |
}), |
| 6043 |
"Intrinsic's corresponding callbr must have intrinsic's parent basic " |
6043 |
"Intrinsic's corresponding callbr must have intrinsic's parent basic " |
| 6044 |
"block in indirect destination list", |
6044 |
"block in indirect destination list", |
| 6045 |
&Call); |
6045 |
&Call); |
| 6046 |
const Instruction &First = *LandingPadBB->begin(); |
6046 |
const Instruction &First = *LandingPadBB->begin(); |
| 6047 |
Check(&First == &Call, "No other instructions may proceed intrinsic", |
6047 |
Check(&First == &Call, "No other instructions may proceed intrinsic", |
| 6048 |
&Call); |
6048 |
&Call); |
| 6049 |
break; |
6049 |
break; |
| 6050 |
} |
6050 |
} |
| 6051 |
case Intrinsic::amdgcn_cs_chain: { |
6051 |
case Intrinsic::amdgcn_cs_chain: { |
| 6052 |
auto CallerCC = Call.getCaller()->getCallingConv(); |
6052 |
auto CallerCC = Call.getCaller()->getCallingConv(); |
| 6053 |
switch (CallerCC) { |
6053 |
switch (CallerCC) { |
| 6054 |
case CallingConv::AMDGPU_CS: |
6054 |
case CallingConv::AMDGPU_CS: |
| 6055 |
case CallingConv::AMDGPU_CS_Chain: |
6055 |
case CallingConv::AMDGPU_CS_Chain: |
| 6056 |
case CallingConv::AMDGPU_CS_ChainPreserve: |
6056 |
case CallingConv::AMDGPU_CS_ChainPreserve: |
| 6057 |
break; |
6057 |
break; |
| 6058 |
default: |
6058 |
default: |
| 6059 |
CheckFailed("Intrinsic can only be used from functions with the " |
6059 |
CheckFailed("Intrinsic can only be used from functions with the " |
| 6060 |
"amdgpu_cs, amdgpu_cs_chain or amdgpu_cs_chain_preserve " |
6060 |
"amdgpu_cs, amdgpu_cs_chain or amdgpu_cs_chain_preserve " |
| 6061 |
"calling conventions", |
6061 |
"calling conventions", |
| 6062 |
&Call); |
6062 |
&Call); |
| 6063 |
break; |
6063 |
break; |
| 6064 |
} |
6064 |
} |
| 6065 |
break; |
6065 |
break; |
| 6066 |
} |
6066 |
} |
| 6067 |
case Intrinsic::experimental_convergence_entry: |
6067 |
case Intrinsic::experimental_convergence_entry: |
| 6068 |
Check(Call.getFunction()->isConvergent(), |
6068 |
Check(Call.getFunction()->isConvergent(), |
| 6069 |
"Entry intrinsic can occur only in a convergent function.", &Call); |
6069 |
"Entry intrinsic can occur only in a convergent function.", &Call); |
| 6070 |
Check(Call.getParent()->isEntryBlock(), |
6070 |
Check(Call.getParent()->isEntryBlock(), |
| 6071 |
"Entry intrinsic must occur in the entry block.", &Call); |
6071 |
"Entry intrinsic must occur in the entry block.", &Call); |
| 6072 |
Check(Call.getParent()->getFirstNonPHI() == &Call, |
6072 |
Check(Call.getParent()->getFirstNonPHI() == &Call, |
| 6073 |
"Entry intrinsic must occur at the start of the basic block.", &Call); |
6073 |
"Entry intrinsic must occur at the start of the basic block.", &Call); |
| 6074 |
LLVM_FALLTHROUGH; |
6074 |
LLVM_FALLTHROUGH; |
| 6075 |
case Intrinsic::experimental_convergence_anchor: |
6075 |
case Intrinsic::experimental_convergence_anchor: |
| 6076 |
Check(!Call.getOperandBundle(LLVMContext::OB_convergencectrl), |
6076 |
Check(!Call.getOperandBundle(LLVMContext::OB_convergencectrl), |
| 6077 |
"Entry or anchor intrinsic must not have a convergencectrl bundle.", |
6077 |
"Entry or anchor intrinsic must not have a convergencectrl bundle.", |
| 6078 |
&Call); |
6078 |
&Call); |
| 6079 |
break; |
6079 |
break; |
| 6080 |
case Intrinsic::experimental_convergence_loop: |
6080 |
case Intrinsic::experimental_convergence_loop: |
| 6081 |
Check(Call.getOperandBundle(LLVMContext::OB_convergencectrl), |
6081 |
Check(Call.getOperandBundle(LLVMContext::OB_convergencectrl), |
| 6082 |
"Loop intrinsic must have a convergencectrl bundle.", &Call); |
6082 |
"Loop intrinsic must have a convergencectrl bundle.", &Call); |
| 6083 |
Check(Call.getParent()->getFirstNonPHI() == &Call, |
6083 |
Check(Call.getParent()->getFirstNonPHI() == &Call, |
| 6084 |
"Loop intrinsic must occur at the start of the basic block.", &Call); |
6084 |
"Loop intrinsic must occur at the start of the basic block.", &Call); |
| 6085 |
break; |
6085 |
break; |
| 6086 |
}; |
6086 |
}; |
| 6087 |
|
6087 |
|
| 6088 |
// Verify that there aren't any unmediated control transfers between funclets. |
6088 |
// Verify that there aren't any unmediated control transfers between funclets. |
| 6089 |
if (IntrinsicInst::mayLowerToFunctionCall(ID)) { |
6089 |
if (IntrinsicInst::mayLowerToFunctionCall(ID)) { |
| 6090 |
Function *F = Call.getParent()->getParent(); |
6090 |
Function *F = Call.getParent()->getParent(); |
| 6091 |
if (F->hasPersonalityFn() && |
6091 |
if (F->hasPersonalityFn() && |
| 6092 |
isScopedEHPersonality(classifyEHPersonality(F->getPersonalityFn()))) { |
6092 |
isScopedEHPersonality(classifyEHPersonality(F->getPersonalityFn()))) { |
| 6093 |
// Run EH funclet coloring on-demand and cache results for other intrinsic |
6093 |
// Run EH funclet coloring on-demand and cache results for other intrinsic |
| 6094 |
// calls in this function |
6094 |
// calls in this function |
| 6095 |
if (BlockEHFuncletColors.empty()) |
6095 |
if (BlockEHFuncletColors.empty()) |
| 6096 |
BlockEHFuncletColors = colorEHFunclets(*F); |
6096 |
BlockEHFuncletColors = colorEHFunclets(*F); |
| 6097 |
|
6097 |
|
| 6098 |
// Check for catch-/cleanup-pad in first funclet block |
6098 |
// Check for catch-/cleanup-pad in first funclet block |
| 6099 |
bool InEHFunclet = false; |
6099 |
bool InEHFunclet = false; |
| 6100 |
BasicBlock *CallBB = Call.getParent(); |
6100 |
BasicBlock *CallBB = Call.getParent(); |
| 6101 |
const ColorVector &CV = BlockEHFuncletColors.find(CallBB)->second; |
6101 |
const ColorVector &CV = BlockEHFuncletColors.find(CallBB)->second; |
| 6102 |
assert(CV.size() > 0 && "Uncolored block"); |
6102 |
assert(CV.size() > 0 && "Uncolored block"); |
| 6103 |
for (BasicBlock *ColorFirstBB : CV) |
6103 |
for (BasicBlock *ColorFirstBB : CV) |
| 6104 |
if (dyn_cast_or_null(ColorFirstBB->getFirstNonPHI())) |
6104 |
if (dyn_cast_or_null(ColorFirstBB->getFirstNonPHI())) |
| 6105 |
InEHFunclet = true; |
6105 |
InEHFunclet = true; |
| 6106 |
|
6106 |
|
| 6107 |
// Check for funclet operand bundle |
6107 |
// Check for funclet operand bundle |
| 6108 |
bool HasToken = false; |
6108 |
bool HasToken = false; |
| 6109 |
for (unsigned I = 0, E = Call.getNumOperandBundles(); I != E; ++I) |
6109 |
for (unsigned I = 0, E = Call.getNumOperandBundles(); I != E; ++I) |
| 6110 |
if (Call.getOperandBundleAt(I).getTagID() == LLVMContext::OB_funclet) |
6110 |
if (Call.getOperandBundleAt(I).getTagID() == LLVMContext::OB_funclet) |
| 6111 |
HasToken = true; |
6111 |
HasToken = true; |
| 6112 |
|
6112 |
|
| 6113 |
// This would cause silent code truncation in WinEHPrepare |
6113 |
// This would cause silent code truncation in WinEHPrepare |
| 6114 |
if (InEHFunclet) |
6114 |
if (InEHFunclet) |
| 6115 |
Check(HasToken, "Missing funclet token on intrinsic call", &Call); |
6115 |
Check(HasToken, "Missing funclet token on intrinsic call", &Call); |
| 6116 |
} |
6116 |
} |
| 6117 |
} |
6117 |
} |
| 6118 |
} |
6118 |
} |
| 6119 |
|
6119 |
|
| 6120 |
/// Carefully grab the subprogram from a local scope. |
6120 |
/// Carefully grab the subprogram from a local scope. |
| 6121 |
/// |
6121 |
/// |
| 6122 |
/// This carefully grabs the subprogram from a local scope, avoiding the |
6122 |
/// This carefully grabs the subprogram from a local scope, avoiding the |
| 6123 |
/// built-in assertions that would typically fire. |
6123 |
/// built-in assertions that would typically fire. |
| 6124 |
static DISubprogram *getSubprogram(Metadata *LocalScope) { |
6124 |
static DISubprogram *getSubprogram(Metadata *LocalScope) { |
| 6125 |
if (!LocalScope) |
6125 |
if (!LocalScope) |
| 6126 |
return nullptr; |
6126 |
return nullptr; |
| 6127 |
|
6127 |
|
| 6128 |
if (auto *SP = dyn_cast(LocalScope)) |
6128 |
if (auto *SP = dyn_cast(LocalScope)) |
| 6129 |
return SP; |
6129 |
return SP; |
| 6130 |
|
6130 |
|
| 6131 |
if (auto *LB = dyn_cast(LocalScope)) |
6131 |
if (auto *LB = dyn_cast(LocalScope)) |
| 6132 |
return getSubprogram(LB->getRawScope()); |
6132 |
return getSubprogram(LB->getRawScope()); |
| 6133 |
|
6133 |
|
| 6134 |
// Just return null; broken scope chains are checked elsewhere. |
6134 |
// Just return null; broken scope chains are checked elsewhere. |
| 6135 |
assert(!isa(LocalScope) && "Unknown type of local scope"); |
6135 |
assert(!isa(LocalScope) && "Unknown type of local scope"); |
| 6136 |
return nullptr; |
6136 |
return nullptr; |
| 6137 |
} |
6137 |
} |
| 6138 |
|
6138 |
|
| 6139 |
void Verifier::visitVPIntrinsic(VPIntrinsic &VPI) { |
6139 |
void Verifier::visitVPIntrinsic(VPIntrinsic &VPI) { |
| 6140 |
if (auto *VPCast = dyn_cast(&VPI)) { |
6140 |
if (auto *VPCast = dyn_cast(&VPI)) { |
| 6141 |
auto *RetTy = cast(VPCast->getType()); |
6141 |
auto *RetTy = cast(VPCast->getType()); |
| 6142 |
auto *ValTy = cast(VPCast->getOperand(0)->getType()); |
6142 |
auto *ValTy = cast(VPCast->getOperand(0)->getType()); |
| 6143 |
Check(RetTy->getElementCount() == ValTy->getElementCount(), |
6143 |
Check(RetTy->getElementCount() == ValTy->getElementCount(), |
| 6144 |
"VP cast intrinsic first argument and result vector lengths must be " |
6144 |
"VP cast intrinsic first argument and result vector lengths must be " |
| 6145 |
"equal", |
6145 |
"equal", |
| 6146 |
*VPCast); |
6146 |
*VPCast); |
| 6147 |
|
6147 |
|
| 6148 |
switch (VPCast->getIntrinsicID()) { |
6148 |
switch (VPCast->getIntrinsicID()) { |
| 6149 |
default: |
6149 |
default: |
| 6150 |
llvm_unreachable("Unknown VP cast intrinsic"); |
6150 |
llvm_unreachable("Unknown VP cast intrinsic"); |
| 6151 |
case Intrinsic::vp_trunc: |
6151 |
case Intrinsic::vp_trunc: |
| 6152 |
Check(RetTy->isIntOrIntVectorTy() && ValTy->isIntOrIntVectorTy(), |
6152 |
Check(RetTy->isIntOrIntVectorTy() && ValTy->isIntOrIntVectorTy(), |
| 6153 |
"llvm.vp.trunc intrinsic first argument and result element type " |
6153 |
"llvm.vp.trunc intrinsic first argument and result element type " |
| 6154 |
"must be integer", |
6154 |
"must be integer", |
| 6155 |
*VPCast); |
6155 |
*VPCast); |
| 6156 |
Check(RetTy->getScalarSizeInBits() < ValTy->getScalarSizeInBits(), |
6156 |
Check(RetTy->getScalarSizeInBits() < ValTy->getScalarSizeInBits(), |
| 6157 |
"llvm.vp.trunc intrinsic the bit size of first argument must be " |
6157 |
"llvm.vp.trunc intrinsic the bit size of first argument must be " |
| 6158 |
"larger than the bit size of the return type", |
6158 |
"larger than the bit size of the return type", |
| 6159 |
*VPCast); |
6159 |
*VPCast); |
| 6160 |
break; |
6160 |
break; |
| 6161 |
case Intrinsic::vp_zext: |
6161 |
case Intrinsic::vp_zext: |
| 6162 |
case Intrinsic::vp_sext: |
6162 |
case Intrinsic::vp_sext: |
| 6163 |
Check(RetTy->isIntOrIntVectorTy() && ValTy->isIntOrIntVectorTy(), |
6163 |
Check(RetTy->isIntOrIntVectorTy() && ValTy->isIntOrIntVectorTy(), |
| 6164 |
"llvm.vp.zext or llvm.vp.sext intrinsic first argument and result " |
6164 |
"llvm.vp.zext or llvm.vp.sext intrinsic first argument and result " |
| 6165 |
"element type must be integer", |
6165 |
"element type must be integer", |
| 6166 |
*VPCast); |
6166 |
*VPCast); |
| 6167 |
Check(RetTy->getScalarSizeInBits() > ValTy->getScalarSizeInBits(), |
6167 |
Check(RetTy->getScalarSizeInBits() > ValTy->getScalarSizeInBits(), |
| 6168 |
"llvm.vp.zext or llvm.vp.sext intrinsic the bit size of first " |
6168 |
"llvm.vp.zext or llvm.vp.sext intrinsic the bit size of first " |
| 6169 |
"argument must be smaller than the bit size of the return type", |
6169 |
"argument must be smaller than the bit size of the return type", |
| 6170 |
*VPCast); |
6170 |
*VPCast); |
| 6171 |
break; |
6171 |
break; |
| 6172 |
case Intrinsic::vp_fptoui: |
6172 |
case Intrinsic::vp_fptoui: |
| 6173 |
case Intrinsic::vp_fptosi: |
6173 |
case Intrinsic::vp_fptosi: |
| 6174 |
Check( |
6174 |
Check( |
| 6175 |
RetTy->isIntOrIntVectorTy() && ValTy->isFPOrFPVectorTy(), |
6175 |
RetTy->isIntOrIntVectorTy() && ValTy->isFPOrFPVectorTy(), |
| 6176 |
"llvm.vp.fptoui or llvm.vp.fptosi intrinsic first argument element " |
6176 |
"llvm.vp.fptoui or llvm.vp.fptosi intrinsic first argument element " |
| 6177 |
"type must be floating-point and result element type must be integer", |
6177 |
"type must be floating-point and result element type must be integer", |
| 6178 |
*VPCast); |
6178 |
*VPCast); |
| 6179 |
break; |
6179 |
break; |
| 6180 |
case Intrinsic::vp_uitofp: |
6180 |
case Intrinsic::vp_uitofp: |
| 6181 |
case Intrinsic::vp_sitofp: |
6181 |
case Intrinsic::vp_sitofp: |
| 6182 |
Check( |
6182 |
Check( |
| 6183 |
RetTy->isFPOrFPVectorTy() && ValTy->isIntOrIntVectorTy(), |
6183 |
RetTy->isFPOrFPVectorTy() && ValTy->isIntOrIntVectorTy(), |
| 6184 |
"llvm.vp.uitofp or llvm.vp.sitofp intrinsic first argument element " |
6184 |
"llvm.vp.uitofp or llvm.vp.sitofp intrinsic first argument element " |
| 6185 |
"type must be integer and result element type must be floating-point", |
6185 |
"type must be integer and result element type must be floating-point", |
| 6186 |
*VPCast); |
6186 |
*VPCast); |
| 6187 |
break; |
6187 |
break; |
| 6188 |
case Intrinsic::vp_fptrunc: |
6188 |
case Intrinsic::vp_fptrunc: |
| 6189 |
Check(RetTy->isFPOrFPVectorTy() && ValTy->isFPOrFPVectorTy(), |
6189 |
Check(RetTy->isFPOrFPVectorTy() && ValTy->isFPOrFPVectorTy(), |
| 6190 |
"llvm.vp.fptrunc intrinsic first argument and result element type " |
6190 |
"llvm.vp.fptrunc intrinsic first argument and result element type " |
| 6191 |
"must be floating-point", |
6191 |
"must be floating-point", |
| 6192 |
*VPCast); |
6192 |
*VPCast); |
| 6193 |
Check(RetTy->getScalarSizeInBits() < ValTy->getScalarSizeInBits(), |
6193 |
Check(RetTy->getScalarSizeInBits() < ValTy->getScalarSizeInBits(), |
| 6194 |
"llvm.vp.fptrunc intrinsic the bit size of first argument must be " |
6194 |
"llvm.vp.fptrunc intrinsic the bit size of first argument must be " |
| 6195 |
"larger than the bit size of the return type", |
6195 |
"larger than the bit size of the return type", |
| 6196 |
*VPCast); |
6196 |
*VPCast); |
| 6197 |
break; |
6197 |
break; |
| 6198 |
case Intrinsic::vp_fpext: |
6198 |
case Intrinsic::vp_fpext: |
| 6199 |
Check(RetTy->isFPOrFPVectorTy() && ValTy->isFPOrFPVectorTy(), |
6199 |
Check(RetTy->isFPOrFPVectorTy() && ValTy->isFPOrFPVectorTy(), |
| 6200 |
"llvm.vp.fpext intrinsic first argument and result element type " |
6200 |
"llvm.vp.fpext intrinsic first argument and result element type " |
| 6201 |
"must be floating-point", |
6201 |
"must be floating-point", |
| 6202 |
*VPCast); |
6202 |
*VPCast); |
| 6203 |
Check(RetTy->getScalarSizeInBits() > ValTy->getScalarSizeInBits(), |
6203 |
Check(RetTy->getScalarSizeInBits() > ValTy->getScalarSizeInBits(), |
| 6204 |
"llvm.vp.fpext intrinsic the bit size of first argument must be " |
6204 |
"llvm.vp.fpext intrinsic the bit size of first argument must be " |
| 6205 |
"smaller than the bit size of the return type", |
6205 |
"smaller than the bit size of the return type", |
| 6206 |
*VPCast); |
6206 |
*VPCast); |
| 6207 |
break; |
6207 |
break; |
| 6208 |
case Intrinsic::vp_ptrtoint: |
6208 |
case Intrinsic::vp_ptrtoint: |
| 6209 |
Check(RetTy->isIntOrIntVectorTy() && ValTy->isPtrOrPtrVectorTy(), |
6209 |
Check(RetTy->isIntOrIntVectorTy() && ValTy->isPtrOrPtrVectorTy(), |
| 6210 |
"llvm.vp.ptrtoint intrinsic first argument element type must be " |
6210 |
"llvm.vp.ptrtoint intrinsic first argument element type must be " |
| 6211 |
"pointer and result element type must be integer", |
6211 |
"pointer and result element type must be integer", |
| 6212 |
*VPCast); |
6212 |
*VPCast); |
| 6213 |
break; |
6213 |
break; |
| 6214 |
case Intrinsic::vp_inttoptr: |
6214 |
case Intrinsic::vp_inttoptr: |
| 6215 |
Check(RetTy->isPtrOrPtrVectorTy() && ValTy->isIntOrIntVectorTy(), |
6215 |
Check(RetTy->isPtrOrPtrVectorTy() && ValTy->isIntOrIntVectorTy(), |
| 6216 |
"llvm.vp.inttoptr intrinsic first argument element type must be " |
6216 |
"llvm.vp.inttoptr intrinsic first argument element type must be " |
| 6217 |
"integer and result element type must be pointer", |
6217 |
"integer and result element type must be pointer", |
| 6218 |
*VPCast); |
6218 |
*VPCast); |
| 6219 |
break; |
6219 |
break; |
| 6220 |
} |
6220 |
} |
| 6221 |
} |
6221 |
} |
| 6222 |
if (VPI.getIntrinsicID() == Intrinsic::vp_fcmp) { |
6222 |
if (VPI.getIntrinsicID() == Intrinsic::vp_fcmp) { |
| 6223 |
auto Pred = cast(&VPI)->getPredicate(); |
6223 |
auto Pred = cast(&VPI)->getPredicate(); |
| 6224 |
Check(CmpInst::isFPPredicate(Pred), |
6224 |
Check(CmpInst::isFPPredicate(Pred), |
| 6225 |
"invalid predicate for VP FP comparison intrinsic", &VPI); |
6225 |
"invalid predicate for VP FP comparison intrinsic", &VPI); |
| 6226 |
} |
6226 |
} |
| 6227 |
if (VPI.getIntrinsicID() == Intrinsic::vp_icmp) { |
6227 |
if (VPI.getIntrinsicID() == Intrinsic::vp_icmp) { |
| 6228 |
auto Pred = cast(&VPI)->getPredicate(); |
6228 |
auto Pred = cast(&VPI)->getPredicate(); |
| 6229 |
Check(CmpInst::isIntPredicate(Pred), |
6229 |
Check(CmpInst::isIntPredicate(Pred), |
| 6230 |
"invalid predicate for VP integer comparison intrinsic", &VPI); |
6230 |
"invalid predicate for VP integer comparison intrinsic", &VPI); |
| 6231 |
} |
6231 |
} |
| 6232 |
} |
6232 |
} |
| 6233 |
|
6233 |
|
| 6234 |
void Verifier::visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI) { |
6234 |
void Verifier::visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI) { |
| 6235 |
unsigned NumOperands; |
6235 |
unsigned NumOperands; |
| 6236 |
bool HasRoundingMD; |
6236 |
bool HasRoundingMD; |
| 6237 |
switch (FPI.getIntrinsicID()) { |
6237 |
switch (FPI.getIntrinsicID()) { |
| 6238 |
#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \ |
6238 |
#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \ |
| 6239 |
case Intrinsic::INTRINSIC: \ |
6239 |
case Intrinsic::INTRINSIC: \ |
| 6240 |
NumOperands = NARG; \ |
6240 |
NumOperands = NARG; \ |
| 6241 |
HasRoundingMD = ROUND_MODE; \ |
6241 |
HasRoundingMD = ROUND_MODE; \ |
| 6242 |
break; |
6242 |
break; |
| 6243 |
#include "llvm/IR/ConstrainedOps.def" |
6243 |
#include "llvm/IR/ConstrainedOps.def" |
| 6244 |
default: |
6244 |
default: |
| 6245 |
llvm_unreachable("Invalid constrained FP intrinsic!"); |
6245 |
llvm_unreachable("Invalid constrained FP intrinsic!"); |
| 6246 |
} |
6246 |
} |
| 6247 |
NumOperands += (1 + HasRoundingMD); |
6247 |
NumOperands += (1 + HasRoundingMD); |
| 6248 |
// Compare intrinsics carry an extra predicate metadata operand. |
6248 |
// Compare intrinsics carry an extra predicate metadata operand. |
| 6249 |
if (isa(FPI)) |
6249 |
if (isa(FPI)) |
| 6250 |
NumOperands += 1; |
6250 |
NumOperands += 1; |
| 6251 |
Check((FPI.arg_size() == NumOperands), |
6251 |
Check((FPI.arg_size() == NumOperands), |
| 6252 |
"invalid arguments for constrained FP intrinsic", &FPI); |
6252 |
"invalid arguments for constrained FP intrinsic", &FPI); |
| 6253 |
|
6253 |
|
| 6254 |
switch (FPI.getIntrinsicID()) { |
6254 |
switch (FPI.getIntrinsicID()) { |
| 6255 |
case Intrinsic::experimental_constrained_lrint: |
6255 |
case Intrinsic::experimental_constrained_lrint: |
| 6256 |
case Intrinsic::experimental_constrained_llrint: { |
6256 |
case Intrinsic::experimental_constrained_llrint: { |
| 6257 |
Type *ValTy = FPI.getArgOperand(0)->getType(); |
6257 |
Type *ValTy = FPI.getArgOperand(0)->getType(); |
| 6258 |
Type *ResultTy = FPI.getType(); |
6258 |
Type *ResultTy = FPI.getType(); |
| 6259 |
Check(!ValTy->isVectorTy() && !ResultTy->isVectorTy(), |
6259 |
Check(!ValTy->isVectorTy() && !ResultTy->isVectorTy(), |
| 6260 |
"Intrinsic does not support vectors", &FPI); |
6260 |
"Intrinsic does not support vectors", &FPI); |
| 6261 |
} |
6261 |
} |
| 6262 |
break; |
6262 |
break; |
| 6263 |
|
6263 |
|
| 6264 |
case Intrinsic::experimental_constrained_lround: |
6264 |
case Intrinsic::experimental_constrained_lround: |
| 6265 |
case Intrinsic::experimental_constrained_llround: { |
6265 |
case Intrinsic::experimental_constrained_llround: { |
| 6266 |
Type *ValTy = FPI.getArgOperand(0)->getType(); |
6266 |
Type *ValTy = FPI.getArgOperand(0)->getType(); |
| 6267 |
Type *ResultTy = FPI.getType(); |
6267 |
Type *ResultTy = FPI.getType(); |
| 6268 |
Check(!ValTy->isVectorTy() && !ResultTy->isVectorTy(), |
6268 |
Check(!ValTy->isVectorTy() && !ResultTy->isVectorTy(), |
| 6269 |
"Intrinsic does not support vectors", &FPI); |
6269 |
"Intrinsic does not support vectors", &FPI); |
| 6270 |
break; |
6270 |
break; |
| 6271 |
} |
6271 |
} |
| 6272 |
|
6272 |
|
| 6273 |
case Intrinsic::experimental_constrained_fcmp: |
6273 |
case Intrinsic::experimental_constrained_fcmp: |
| 6274 |
case Intrinsic::experimental_constrained_fcmps: { |
6274 |
case Intrinsic::experimental_constrained_fcmps: { |
| 6275 |
auto Pred = cast(&FPI)->getPredicate(); |
6275 |
auto Pred = cast(&FPI)->getPredicate(); |
| 6276 |
Check(CmpInst::isFPPredicate(Pred), |
6276 |
Check(CmpInst::isFPPredicate(Pred), |
| 6277 |
"invalid predicate for constrained FP comparison intrinsic", &FPI); |
6277 |
"invalid predicate for constrained FP comparison intrinsic", &FPI); |
| 6278 |
break; |
6278 |
break; |
| 6279 |
} |
6279 |
} |
| 6280 |
|
6280 |
|
| 6281 |
case Intrinsic::experimental_constrained_fptosi: |
6281 |
case Intrinsic::experimental_constrained_fptosi: |
| 6282 |
case Intrinsic::experimental_constrained_fptoui: { |
6282 |
case Intrinsic::experimental_constrained_fptoui: { |
| 6283 |
Value *Operand = FPI.getArgOperand(0); |
6283 |
Value *Operand = FPI.getArgOperand(0); |
| 6284 |
ElementCount SrcEC; |
6284 |
ElementCount SrcEC; |
| 6285 |
Check(Operand->getType()->isFPOrFPVectorTy(), |
6285 |
Check(Operand->getType()->isFPOrFPVectorTy(), |
| 6286 |
"Intrinsic first argument must be floating point", &FPI); |
6286 |
"Intrinsic first argument must be floating point", &FPI); |
| 6287 |
if (auto *OperandT = dyn_cast(Operand->getType())) { |
6287 |
if (auto *OperandT = dyn_cast(Operand->getType())) { |
| 6288 |
SrcEC = cast(OperandT)->getElementCount(); |
6288 |
SrcEC = cast(OperandT)->getElementCount(); |
| 6289 |
} |
6289 |
} |
| 6290 |
|
6290 |
|
| 6291 |
Operand = &FPI; |
6291 |
Operand = &FPI; |
| 6292 |
Check(SrcEC.isNonZero() == Operand->getType()->isVectorTy(), |
6292 |
Check(SrcEC.isNonZero() == Operand->getType()->isVectorTy(), |
| 6293 |
"Intrinsic first argument and result disagree on vector use", &FPI); |
6293 |
"Intrinsic first argument and result disagree on vector use", &FPI); |
| 6294 |
Check(Operand->getType()->isIntOrIntVectorTy(), |
6294 |
Check(Operand->getType()->isIntOrIntVectorTy(), |
| 6295 |
"Intrinsic result must be an integer", &FPI); |
6295 |
"Intrinsic result must be an integer", &FPI); |
| 6296 |
if (auto *OperandT = dyn_cast(Operand->getType())) { |
6296 |
if (auto *OperandT = dyn_cast(Operand->getType())) { |
| 6297 |
Check(SrcEC == cast(OperandT)->getElementCount(), |
6297 |
Check(SrcEC == cast(OperandT)->getElementCount(), |
| 6298 |
"Intrinsic first argument and result vector lengths must be equal", |
6298 |
"Intrinsic first argument and result vector lengths must be equal", |
| 6299 |
&FPI); |
6299 |
&FPI); |
| 6300 |
} |
6300 |
} |
| 6301 |
} |
6301 |
} |
| 6302 |
break; |
6302 |
break; |
| 6303 |
|
6303 |
|
| 6304 |
case Intrinsic::experimental_constrained_sitofp: |
6304 |
case Intrinsic::experimental_constrained_sitofp: |
| 6305 |
case Intrinsic::experimental_constrained_uitofp: { |
6305 |
case Intrinsic::experimental_constrained_uitofp: { |
| 6306 |
Value *Operand = FPI.getArgOperand(0); |
6306 |
Value *Operand = FPI.getArgOperand(0); |
| 6307 |
ElementCount SrcEC; |
6307 |
ElementCount SrcEC; |
| 6308 |
Check(Operand->getType()->isIntOrIntVectorTy(), |
6308 |
Check(Operand->getType()->isIntOrIntVectorTy(), |
| 6309 |
"Intrinsic first argument must be integer", &FPI); |
6309 |
"Intrinsic first argument must be integer", &FPI); |
| 6310 |
if (auto *OperandT = dyn_cast(Operand->getType())) { |
6310 |
if (auto *OperandT = dyn_cast(Operand->getType())) { |
| 6311 |
SrcEC = cast(OperandT)->getElementCount(); |
6311 |
SrcEC = cast(OperandT)->getElementCount(); |
| 6312 |
} |
6312 |
} |
| 6313 |
|
6313 |
|
| 6314 |
Operand = &FPI; |
6314 |
Operand = &FPI; |
| 6315 |
Check(SrcEC.isNonZero() == Operand->getType()->isVectorTy(), |
6315 |
Check(SrcEC.isNonZero() == Operand->getType()->isVectorTy(), |
| 6316 |
"Intrinsic first argument and result disagree on vector use", &FPI); |
6316 |
"Intrinsic first argument and result disagree on vector use", &FPI); |
| 6317 |
Check(Operand->getType()->isFPOrFPVectorTy(), |
6317 |
Check(Operand->getType()->isFPOrFPVectorTy(), |
| 6318 |
"Intrinsic result must be a floating point", &FPI); |
6318 |
"Intrinsic result must be a floating point", &FPI); |
| 6319 |
if (auto *OperandT = dyn_cast(Operand->getType())) { |
6319 |
if (auto *OperandT = dyn_cast(Operand->getType())) { |
| 6320 |
Check(SrcEC == cast(OperandT)->getElementCount(), |
6320 |
Check(SrcEC == cast(OperandT)->getElementCount(), |
| 6321 |
"Intrinsic first argument and result vector lengths must be equal", |
6321 |
"Intrinsic first argument and result vector lengths must be equal", |
| 6322 |
&FPI); |
6322 |
&FPI); |
| 6323 |
} |
6323 |
} |
| 6324 |
} break; |
6324 |
} break; |
| 6325 |
|
6325 |
|
| 6326 |
case Intrinsic::experimental_constrained_fptrunc: |
6326 |
case Intrinsic::experimental_constrained_fptrunc: |
| 6327 |
case Intrinsic::experimental_constrained_fpext: { |
6327 |
case Intrinsic::experimental_constrained_fpext: { |
| 6328 |
Value *Operand = FPI.getArgOperand(0); |
6328 |
Value *Operand = FPI.getArgOperand(0); |
| 6329 |
Type *OperandTy = Operand->getType(); |
6329 |
Type *OperandTy = Operand->getType(); |
| 6330 |
Value *Result = &FPI; |
6330 |
Value *Result = &FPI; |
| 6331 |
Type *ResultTy = Result->getType(); |
6331 |
Type *ResultTy = Result->getType(); |
| 6332 |
Check(OperandTy->isFPOrFPVectorTy(), |
6332 |
Check(OperandTy->isFPOrFPVectorTy(), |
| 6333 |
"Intrinsic first argument must be FP or FP vector", &FPI); |
6333 |
"Intrinsic first argument must be FP or FP vector", &FPI); |
| 6334 |
Check(ResultTy->isFPOrFPVectorTy(), |
6334 |
Check(ResultTy->isFPOrFPVectorTy(), |
| 6335 |
"Intrinsic result must be FP or FP vector", &FPI); |
6335 |
"Intrinsic result must be FP or FP vector", &FPI); |
| 6336 |
Check(OperandTy->isVectorTy() == ResultTy->isVectorTy(), |
6336 |
Check(OperandTy->isVectorTy() == ResultTy->isVectorTy(), |
| 6337 |
"Intrinsic first argument and result disagree on vector use", &FPI); |
6337 |
"Intrinsic first argument and result disagree on vector use", &FPI); |
| 6338 |
if (OperandTy->isVectorTy()) { |
6338 |
if (OperandTy->isVectorTy()) { |
| 6339 |
Check(cast(OperandTy)->getElementCount() == |
6339 |
Check(cast(OperandTy)->getElementCount() == |
| 6340 |
cast(ResultTy)->getElementCount(), |
6340 |
cast(ResultTy)->getElementCount(), |
| 6341 |
"Intrinsic first argument and result vector lengths must be equal", |
6341 |
"Intrinsic first argument and result vector lengths must be equal", |
| 6342 |
&FPI); |
6342 |
&FPI); |
| 6343 |
} |
6343 |
} |
| 6344 |
if (FPI.getIntrinsicID() == Intrinsic::experimental_constrained_fptrunc) { |
6344 |
if (FPI.getIntrinsicID() == Intrinsic::experimental_constrained_fptrunc) { |
| 6345 |
Check(OperandTy->getScalarSizeInBits() > ResultTy->getScalarSizeInBits(), |
6345 |
Check(OperandTy->getScalarSizeInBits() > ResultTy->getScalarSizeInBits(), |
| 6346 |
"Intrinsic first argument's type must be larger than result type", |
6346 |
"Intrinsic first argument's type must be larger than result type", |
| 6347 |
&FPI); |
6347 |
&FPI); |
| 6348 |
} else { |
6348 |
} else { |
| 6349 |
Check(OperandTy->getScalarSizeInBits() < ResultTy->getScalarSizeInBits(), |
6349 |
Check(OperandTy->getScalarSizeInBits() < ResultTy->getScalarSizeInBits(), |
| 6350 |
"Intrinsic first argument's type must be smaller than result type", |
6350 |
"Intrinsic first argument's type must be smaller than result type", |
| 6351 |
&FPI); |
6351 |
&FPI); |
| 6352 |
} |
6352 |
} |
| 6353 |
} |
6353 |
} |
| 6354 |
break; |
6354 |
break; |
| 6355 |
|
6355 |
|
| 6356 |
default: |
6356 |
default: |
| 6357 |
break; |
6357 |
break; |
| 6358 |
} |
6358 |
} |
| 6359 |
|
6359 |
|
| 6360 |
// If a non-metadata argument is passed in a metadata slot then the |
6360 |
// If a non-metadata argument is passed in a metadata slot then the |
| 6361 |
// error will be caught earlier when the incorrect argument doesn't |
6361 |
// error will be caught earlier when the incorrect argument doesn't |
| 6362 |
// match the specification in the intrinsic call table. Thus, no |
6362 |
// match the specification in the intrinsic call table. Thus, no |
| 6363 |
// argument type check is needed here. |
6363 |
// argument type check is needed here. |
| 6364 |
|
6364 |
|
| 6365 |
Check(FPI.getExceptionBehavior().has_value(), |
6365 |
Check(FPI.getExceptionBehavior().has_value(), |
| 6366 |
"invalid exception behavior argument", &FPI); |
6366 |
"invalid exception behavior argument", &FPI); |
| 6367 |
if (HasRoundingMD) { |
6367 |
if (HasRoundingMD) { |
| 6368 |
Check(FPI.getRoundingMode().has_value(), "invalid rounding mode argument", |
6368 |
Check(FPI.getRoundingMode().has_value(), "invalid rounding mode argument", |
| 6369 |
&FPI); |
6369 |
&FPI); |
| 6370 |
} |
6370 |
} |
| 6371 |
} |
6371 |
} |
| 6372 |
|
6372 |
|
| 6373 |
void Verifier::visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII) { |
6373 |
void Verifier::visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII) { |
| 6374 |
auto *MD = DII.getRawLocation(); |
6374 |
auto *MD = DII.getRawLocation(); |
| 6375 |
CheckDI(isa(MD) || isa(MD) || |
6375 |
CheckDI(isa(MD) || isa(MD) || |
| 6376 |
(isa(MD) && !cast(MD)->getNumOperands()), |
6376 |
(isa(MD) && !cast(MD)->getNumOperands()), |
| 6377 |
"invalid llvm.dbg." + Kind + " intrinsic address/value", &DII, MD); |
6377 |
"invalid llvm.dbg." + Kind + " intrinsic address/value", &DII, MD); |
| 6378 |
CheckDI(isa(DII.getRawVariable()), |
6378 |
CheckDI(isa(DII.getRawVariable()), |
| 6379 |
"invalid llvm.dbg." + Kind + " intrinsic variable", &DII, |
6379 |
"invalid llvm.dbg." + Kind + " intrinsic variable", &DII, |
| 6380 |
DII.getRawVariable()); |
6380 |
DII.getRawVariable()); |
| 6381 |
CheckDI(isa(DII.getRawExpression()), |
6381 |
CheckDI(isa(DII.getRawExpression()), |
| 6382 |
"invalid llvm.dbg." + Kind + " intrinsic expression", &DII, |
6382 |
"invalid llvm.dbg." + Kind + " intrinsic expression", &DII, |
| 6383 |
DII.getRawExpression()); |
6383 |
DII.getRawExpression()); |
| 6384 |
|
6384 |
|
| 6385 |
if (auto *DAI = dyn_cast(&DII)) { |
6385 |
if (auto *DAI = dyn_cast(&DII)) { |
| 6386 |
CheckDI(isa(DAI->getRawAssignID()), |
6386 |
CheckDI(isa(DAI->getRawAssignID()), |
| 6387 |
"invalid llvm.dbg.assign intrinsic DIAssignID", &DII, |
6387 |
"invalid llvm.dbg.assign intrinsic DIAssignID", &DII, |
| 6388 |
DAI->getRawAssignID()); |
6388 |
DAI->getRawAssignID()); |
| 6389 |
const auto *RawAddr = DAI->getRawAddress(); |
6389 |
const auto *RawAddr = DAI->getRawAddress(); |
| 6390 |
CheckDI( |
6390 |
CheckDI( |
| 6391 |
isa(RawAddr) || |
6391 |
isa(RawAddr) || |
| 6392 |
(isa(RawAddr) && !cast(RawAddr)->getNumOperands()), |
6392 |
(isa(RawAddr) && !cast(RawAddr)->getNumOperands()), |
| 6393 |
"invalid llvm.dbg.assign intrinsic address", &DII, |
6393 |
"invalid llvm.dbg.assign intrinsic address", &DII, |
| 6394 |
DAI->getRawAddress()); |
6394 |
DAI->getRawAddress()); |
| 6395 |
CheckDI(isa(DAI->getRawAddressExpression()), |
6395 |
CheckDI(isa(DAI->getRawAddressExpression()), |
| 6396 |
"invalid llvm.dbg.assign intrinsic address expression", &DII, |
6396 |
"invalid llvm.dbg.assign intrinsic address expression", &DII, |
| 6397 |
DAI->getRawAddressExpression()); |
6397 |
DAI->getRawAddressExpression()); |
| 6398 |
// All of the linked instructions should be in the same function as DII. |
6398 |
// All of the linked instructions should be in the same function as DII. |
| 6399 |
for (Instruction *I : at::getAssignmentInsts(DAI)) |
6399 |
for (Instruction *I : at::getAssignmentInsts(DAI)) |
| 6400 |
CheckDI(DAI->getFunction() == I->getFunction(), |
6400 |
CheckDI(DAI->getFunction() == I->getFunction(), |
| 6401 |
"inst not in same function as dbg.assign", I, DAI); |
6401 |
"inst not in same function as dbg.assign", I, DAI); |
| 6402 |
} |
6402 |
} |
| 6403 |
|
6403 |
|
| 6404 |
// Ignore broken !dbg attachments; they're checked elsewhere. |
6404 |
// Ignore broken !dbg attachments; they're checked elsewhere. |
| 6405 |
if (MDNode *N = DII.getDebugLoc().getAsMDNode()) |
6405 |
if (MDNode *N = DII.getDebugLoc().getAsMDNode()) |
| 6406 |
if (!isa(N)) |
6406 |
if (!isa(N)) |
| 6407 |
return; |
6407 |
return; |
| 6408 |
|
6408 |
|
| 6409 |
BasicBlock *BB = DII.getParent(); |
6409 |
BasicBlock *BB = DII.getParent(); |
| 6410 |
Function *F = BB ? BB->getParent() : nullptr; |
6410 |
Function *F = BB ? BB->getParent() : nullptr; |
| 6411 |
|
6411 |
|
| 6412 |
// The scopes for variables and !dbg attachments must agree. |
6412 |
// The scopes for variables and !dbg attachments must agree. |
| 6413 |
DILocalVariable *Var = DII.getVariable(); |
6413 |
DILocalVariable *Var = DII.getVariable(); |
| 6414 |
DILocation *Loc = DII.getDebugLoc(); |
6414 |
DILocation *Loc = DII.getDebugLoc(); |
| 6415 |
CheckDI(Loc, "llvm.dbg." + Kind + " intrinsic requires a !dbg attachment", |
6415 |
CheckDI(Loc, "llvm.dbg." + Kind + " intrinsic requires a !dbg attachment", |
| 6416 |
&DII, BB, F); |
6416 |
&DII, BB, F); |
| 6417 |
|
6417 |
|
| 6418 |
DISubprogram *VarSP = getSubprogram(Var->getRawScope()); |
6418 |
DISubprogram *VarSP = getSubprogram(Var->getRawScope()); |
| 6419 |
DISubprogram *LocSP = getSubprogram(Loc->getRawScope()); |
6419 |
DISubprogram *LocSP = getSubprogram(Loc->getRawScope()); |
| 6420 |
if (!VarSP || !LocSP) |
6420 |
if (!VarSP || !LocSP) |
| 6421 |
return; // Broken scope chains are checked elsewhere. |
6421 |
return; // Broken scope chains are checked elsewhere. |
| 6422 |
|
6422 |
|
| 6423 |
CheckDI(VarSP == LocSP, |
6423 |
CheckDI(VarSP == LocSP, |
| 6424 |
"mismatched subprogram between llvm.dbg." + Kind + |
6424 |
"mismatched subprogram between llvm.dbg." + Kind + |
| 6425 |
" variable and !dbg attachment", |
6425 |
" variable and !dbg attachment", |
| 6426 |
&DII, BB, F, Var, Var->getScope()->getSubprogram(), Loc, |
6426 |
&DII, BB, F, Var, Var->getScope()->getSubprogram(), Loc, |
| 6427 |
Loc->getScope()->getSubprogram()); |
6427 |
Loc->getScope()->getSubprogram()); |
| 6428 |
|
6428 |
|
| 6429 |
// This check is redundant with one in visitLocalVariable(). |
6429 |
// This check is redundant with one in visitLocalVariable(). |
| 6430 |
CheckDI(isType(Var->getRawType()), "invalid type ref", Var, |
6430 |
CheckDI(isType(Var->getRawType()), "invalid type ref", Var, |
| 6431 |
Var->getRawType()); |
6431 |
Var->getRawType()); |
| 6432 |
verifyFnArgs(DII); |
6432 |
verifyFnArgs(DII); |
| 6433 |
} |
6433 |
} |
| 6434 |
|
6434 |
|
| 6435 |
void Verifier::visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI) { |
6435 |
void Verifier::visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI) { |
| 6436 |
CheckDI(isa(DLI.getRawLabel()), |
6436 |
CheckDI(isa(DLI.getRawLabel()), |
| 6437 |
"invalid llvm.dbg." + Kind + " intrinsic variable", &DLI, |
6437 |
"invalid llvm.dbg." + Kind + " intrinsic variable", &DLI, |
| 6438 |
DLI.getRawLabel()); |
6438 |
DLI.getRawLabel()); |
| 6439 |
|
6439 |
|
| 6440 |
// Ignore broken !dbg attachments; they're checked elsewhere. |
6440 |
// Ignore broken !dbg attachments; they're checked elsewhere. |
| 6441 |
if (MDNode *N = DLI.getDebugLoc().getAsMDNode()) |
6441 |
if (MDNode *N = DLI.getDebugLoc().getAsMDNode()) |
| 6442 |
if (!isa(N)) |
6442 |
if (!isa(N)) |
| 6443 |
return; |
6443 |
return; |
| 6444 |
|
6444 |
|
| 6445 |
BasicBlock *BB = DLI.getParent(); |
6445 |
BasicBlock *BB = DLI.getParent(); |
| 6446 |
Function *F = BB ? BB->getParent() : nullptr; |
6446 |
Function *F = BB ? BB->getParent() : nullptr; |
| 6447 |
|
6447 |
|
| 6448 |
// The scopes for variables and !dbg attachments must agree. |
6448 |
// The scopes for variables and !dbg attachments must agree. |
| 6449 |
DILabel *Label = DLI.getLabel(); |
6449 |
DILabel *Label = DLI.getLabel(); |
| 6450 |
DILocation *Loc = DLI.getDebugLoc(); |
6450 |
DILocation *Loc = DLI.getDebugLoc(); |
| 6451 |
Check(Loc, "llvm.dbg." + Kind + " intrinsic requires a !dbg attachment", &DLI, |
6451 |
Check(Loc, "llvm.dbg." + Kind + " intrinsic requires a !dbg attachment", &DLI, |
| 6452 |
BB, F); |
6452 |
BB, F); |
| 6453 |
|
6453 |
|
| 6454 |
DISubprogram *LabelSP = getSubprogram(Label->getRawScope()); |
6454 |
DISubprogram *LabelSP = getSubprogram(Label->getRawScope()); |
| 6455 |
DISubprogram *LocSP = getSubprogram(Loc->getRawScope()); |
6455 |
DISubprogram *LocSP = getSubprogram(Loc->getRawScope()); |
| 6456 |
if (!LabelSP || !LocSP) |
6456 |
if (!LabelSP || !LocSP) |
| 6457 |
return; |
6457 |
return; |
| 6458 |
|
6458 |
|
| 6459 |
CheckDI(LabelSP == LocSP, |
6459 |
CheckDI(LabelSP == LocSP, |
| 6460 |
"mismatched subprogram between llvm.dbg." + Kind + |
6460 |
"mismatched subprogram between llvm.dbg." + Kind + |
| 6461 |
" label and !dbg attachment", |
6461 |
" label and !dbg attachment", |
| 6462 |
&DLI, BB, F, Label, Label->getScope()->getSubprogram(), Loc, |
6462 |
&DLI, BB, F, Label, Label->getScope()->getSubprogram(), Loc, |
| 6463 |
Loc->getScope()->getSubprogram()); |
6463 |
Loc->getScope()->getSubprogram()); |
| 6464 |
} |
6464 |
} |
| 6465 |
|
6465 |
|
| 6466 |
void Verifier::verifyFragmentExpression(const DbgVariableIntrinsic &I) { |
6466 |
void Verifier::verifyFragmentExpression(const DbgVariableIntrinsic &I) { |
| 6467 |
DILocalVariable *V = dyn_cast_or_null(I.getRawVariable()); |
6467 |
DILocalVariable *V = dyn_cast_or_null(I.getRawVariable()); |
| 6468 |
DIExpression *E = dyn_cast_or_null(I.getRawExpression()); |
6468 |
DIExpression *E = dyn_cast_or_null(I.getRawExpression()); |
| 6469 |
|
6469 |
|
| 6470 |
// We don't know whether this intrinsic verified correctly. |
6470 |
// We don't know whether this intrinsic verified correctly. |
| 6471 |
if (!V || !E || !E->isValid()) |
6471 |
if (!V || !E || !E->isValid()) |
| 6472 |
return; |
6472 |
return; |
| 6473 |
|
6473 |
|
| 6474 |
// Nothing to do if this isn't a DW_OP_LLVM_fragment expression. |
6474 |
// Nothing to do if this isn't a DW_OP_LLVM_fragment expression. |
| 6475 |
auto Fragment = E->getFragmentInfo(); |
6475 |
auto Fragment = E->getFragmentInfo(); |
| 6476 |
if (!Fragment) |
6476 |
if (!Fragment) |
| 6477 |
return; |
6477 |
return; |
| 6478 |
|
6478 |
|
| 6479 |
// The frontend helps out GDB by emitting the members of local anonymous |
6479 |
// The frontend helps out GDB by emitting the members of local anonymous |
| 6480 |
// unions as artificial local variables with shared storage. When SROA splits |
6480 |
// unions as artificial local variables with shared storage. When SROA splits |
| 6481 |
// the storage for artificial local variables that are smaller than the entire |
6481 |
// the storage for artificial local variables that are smaller than the entire |
| 6482 |
// union, the overhang piece will be outside of the allotted space for the |
6482 |
// union, the overhang piece will be outside of the allotted space for the |
| 6483 |
// variable and this check fails. |
6483 |
// variable and this check fails. |
| 6484 |
// FIXME: Remove this check as soon as clang stops doing this; it hides bugs. |
6484 |
// FIXME: Remove this check as soon as clang stops doing this; it hides bugs. |
| 6485 |
if (V->isArtificial()) |
6485 |
if (V->isArtificial()) |
| 6486 |
return; |
6486 |
return; |
| 6487 |
|
6487 |
|
| 6488 |
verifyFragmentExpression(*V, *Fragment, &I); |
6488 |
verifyFragmentExpression(*V, *Fragment, &I); |
| 6489 |
} |
6489 |
} |
| 6490 |
|
6490 |
|
| 6491 |
template |
6491 |
template |
| 6492 |
void Verifier::verifyFragmentExpression(const DIVariable &V, |
6492 |
void Verifier::verifyFragmentExpression(const DIVariable &V, |
| 6493 |
DIExpression::FragmentInfo Fragment, |
6493 |
DIExpression::FragmentInfo Fragment, |
| 6494 |
ValueOrMetadata *Desc) { |
6494 |
ValueOrMetadata *Desc) { |
| 6495 |
// If there's no size, the type is broken, but that should be checked |
6495 |
// If there's no size, the type is broken, but that should be checked |
| 6496 |
// elsewhere. |
6496 |
// elsewhere. |
| 6497 |
auto VarSize = V.getSizeInBits(); |
6497 |
auto VarSize = V.getSizeInBits(); |
| 6498 |
if (!VarSize) |
6498 |
if (!VarSize) |
| 6499 |
return; |
6499 |
return; |
| 6500 |
|
6500 |
|
| 6501 |
unsigned FragSize = Fragment.SizeInBits; |
6501 |
unsigned FragSize = Fragment.SizeInBits; |
| 6502 |
unsigned FragOffset = Fragment.OffsetInBits; |
6502 |
unsigned FragOffset = Fragment.OffsetInBits; |
| 6503 |
CheckDI(FragSize + FragOffset <= *VarSize, |
6503 |
CheckDI(FragSize + FragOffset <= *VarSize, |
| 6504 |
"fragment is larger than or outside of variable", Desc, &V); |
6504 |
"fragment is larger than or outside of variable", Desc, &V); |
| 6505 |
CheckDI(FragSize != *VarSize, "fragment covers entire variable", Desc, &V); |
6505 |
CheckDI(FragSize != *VarSize, "fragment covers entire variable", Desc, &V); |
| 6506 |
} |
6506 |
} |
| 6507 |
|
6507 |
|
| 6508 |
void Verifier::verifyFnArgs(const DbgVariableIntrinsic &I) { |
6508 |
void Verifier::verifyFnArgs(const DbgVariableIntrinsic &I) { |
| 6509 |
// This function does not take the scope of noninlined function arguments into |
6509 |
// This function does not take the scope of noninlined function arguments into |
| 6510 |
// account. Don't run it if current function is nodebug, because it may |
6510 |
// account. Don't run it if current function is nodebug, because it may |
| 6511 |
// contain inlined debug intrinsics. |
6511 |
// contain inlined debug intrinsics. |
| 6512 |
if (!HasDebugInfo) |
6512 |
if (!HasDebugInfo) |
| 6513 |
return; |
6513 |
return; |
| 6514 |
|
6514 |
|
| 6515 |
// For performance reasons only check non-inlined ones. |
6515 |
// For performance reasons only check non-inlined ones. |
| 6516 |
if (I.getDebugLoc()->getInlinedAt()) |
6516 |
if (I.getDebugLoc()->getInlinedAt()) |
| 6517 |
return; |
6517 |
return; |
| 6518 |
|
6518 |
|
| 6519 |
DILocalVariable *Var = I.getVariable(); |
6519 |
DILocalVariable *Var = I.getVariable(); |
| 6520 |
CheckDI(Var, "dbg intrinsic without variable"); |
6520 |
CheckDI(Var, "dbg intrinsic without variable"); |
| 6521 |
|
6521 |
|
| 6522 |
unsigned ArgNo = Var->getArg(); |
6522 |
unsigned ArgNo = Var->getArg(); |
| 6523 |
if (!ArgNo) |
6523 |
if (!ArgNo) |
| 6524 |
return; |
6524 |
return; |
| 6525 |
|
6525 |
|
| 6526 |
// Verify there are no duplicate function argument debug info entries. |
6526 |
// Verify there are no duplicate function argument debug info entries. |
| 6527 |
// These will cause hard-to-debug assertions in the DWARF backend. |
6527 |
// These will cause hard-to-debug assertions in the DWARF backend. |
| 6528 |
if (DebugFnArgs.size() < ArgNo) |
6528 |
if (DebugFnArgs.size() < ArgNo) |
| 6529 |
DebugFnArgs.resize(ArgNo, nullptr); |
6529 |
DebugFnArgs.resize(ArgNo, nullptr); |
| 6530 |
|
6530 |
|
| 6531 |
auto *Prev = DebugFnArgs[ArgNo - 1]; |
6531 |
auto *Prev = DebugFnArgs[ArgNo - 1]; |
| 6532 |
DebugFnArgs[ArgNo - 1] = Var; |
6532 |
DebugFnArgs[ArgNo - 1] = Var; |
| 6533 |
CheckDI(!Prev || (Prev == Var), "conflicting debug info for argument", &I, |
6533 |
CheckDI(!Prev || (Prev == Var), "conflicting debug info for argument", &I, |
| 6534 |
Prev, Var); |
6534 |
Prev, Var); |
| 6535 |
} |
6535 |
} |
| 6536 |
|
6536 |
|
| 6537 |
void Verifier::verifyNotEntryValue(const DbgVariableIntrinsic &I) { |
6537 |
void Verifier::verifyNotEntryValue(const DbgVariableIntrinsic &I) { |
| 6538 |
DIExpression *E = dyn_cast_or_null(I.getRawExpression()); |
6538 |
DIExpression *E = dyn_cast_or_null(I.getRawExpression()); |
| 6539 |
|
6539 |
|
| 6540 |
// We don't know whether this intrinsic verified correctly. |
6540 |
// We don't know whether this intrinsic verified correctly. |
| 6541 |
if (!E || !E->isValid()) |
6541 |
if (!E || !E->isValid()) |
| 6542 |
return; |
6542 |
return; |
| 6543 |
|
6543 |
|
| 6544 |
// We allow EntryValues for swift async arguments, as they have an |
6544 |
// We allow EntryValues for swift async arguments, as they have an |
| 6545 |
// ABI-guarantee to be turned into a specific register. |
6545 |
// ABI-guarantee to be turned into a specific register. |
| 6546 |
if (isa(I.getRawLocation())) |
6546 |
if (isa(I.getRawLocation())) |
| 6547 |
if (auto *ArgLoc = dyn_cast_or_null(I.getVariableLocationOp(0)); |
6547 |
if (auto *ArgLoc = dyn_cast_or_null(I.getVariableLocationOp(0)); |
| 6548 |
ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync)) |
6548 |
ArgLoc && ArgLoc->hasAttribute(Attribute::SwiftAsync)) |
| 6549 |
return; |
6549 |
return; |
| 6550 |
|
6550 |
|
| 6551 |
CheckDI(!E->isEntryValue(), |
6551 |
CheckDI(!E->isEntryValue(), |
| 6552 |
"Entry values are only allowed in MIR unless they target a " |
6552 |
"Entry values are only allowed in MIR unless they target a " |
| 6553 |
"swiftasync Argument", |
6553 |
"swiftasync Argument", |
| 6554 |
&I); |
6554 |
&I); |
| 6555 |
} |
6555 |
} |
| 6556 |
|
6556 |
|
| 6557 |
void Verifier::verifyCompileUnits() { |
6557 |
void Verifier::verifyCompileUnits() { |
| 6558 |
// When more than one Module is imported into the same context, such as during |
6558 |
// When more than one Module is imported into the same context, such as during |
| 6559 |
// an LTO build before linking the modules, ODR type uniquing may cause types |
6559 |
// an LTO build before linking the modules, ODR type uniquing may cause types |
| 6560 |
// to point to a different CU. This check does not make sense in this case. |
6560 |
// to point to a different CU. This check does not make sense in this case. |
| 6561 |
if (M.getContext().isODRUniquingDebugTypes()) |
6561 |
if (M.getContext().isODRUniquingDebugTypes()) |
| 6562 |
return; |
6562 |
return; |
| 6563 |
auto *CUs = M.getNamedMetadata("llvm.dbg.cu"); |
6563 |
auto *CUs = M.getNamedMetadata("llvm.dbg.cu"); |
| 6564 |
SmallPtrSet Listed; |
6564 |
SmallPtrSet Listed; |
| 6565 |
if (CUs) |
6565 |
if (CUs) |
| 6566 |
Listed.insert(CUs->op_begin(), CUs->op_end()); |
6566 |
Listed.insert(CUs->op_begin(), CUs->op_end()); |
| 6567 |
for (const auto *CU : CUVisited) |
6567 |
for (const auto *CU : CUVisited) |
| 6568 |
CheckDI(Listed.count(CU), "DICompileUnit not listed in llvm.dbg.cu", CU); |
6568 |
CheckDI(Listed.count(CU), "DICompileUnit not listed in llvm.dbg.cu", CU); |
| 6569 |
CUVisited.clear(); |
6569 |
CUVisited.clear(); |
| 6570 |
} |
6570 |
} |
| 6571 |
|
6571 |
|
| 6572 |
void Verifier::verifyDeoptimizeCallingConvs() { |
6572 |
void Verifier::verifyDeoptimizeCallingConvs() { |
| 6573 |
if (DeoptimizeDeclarations.empty()) |
6573 |
if (DeoptimizeDeclarations.empty()) |
| 6574 |
return; |
6574 |
return; |
| 6575 |
|
6575 |
|
| 6576 |
const Function *First = DeoptimizeDeclarations[0]; |
6576 |
const Function *First = DeoptimizeDeclarations[0]; |
| 6577 |
for (const auto *F : ArrayRef(DeoptimizeDeclarations).slice(1)) { |
6577 |
for (const auto *F : ArrayRef(DeoptimizeDeclarations).slice(1)) { |
| 6578 |
Check(First->getCallingConv() == F->getCallingConv(), |
6578 |
Check(First->getCallingConv() == F->getCallingConv(), |
| 6579 |
"All llvm.experimental.deoptimize declarations must have the same " |
6579 |
"All llvm.experimental.deoptimize declarations must have the same " |
| 6580 |
"calling convention", |
6580 |
"calling convention", |
| 6581 |
First, F); |
6581 |
First, F); |
| 6582 |
} |
6582 |
} |
| 6583 |
} |
6583 |
} |
| 6584 |
|
6584 |
|
| 6585 |
void Verifier::verifyAttachedCallBundle(const CallBase &Call, |
6585 |
void Verifier::verifyAttachedCallBundle(const CallBase &Call, |
| 6586 |
const OperandBundleUse &BU) { |
6586 |
const OperandBundleUse &BU) { |
| 6587 |
FunctionType *FTy = Call.getFunctionType(); |
6587 |
FunctionType *FTy = Call.getFunctionType(); |
| 6588 |
|
6588 |
|
| 6589 |
Check((FTy->getReturnType()->isPointerTy() || |
6589 |
Check((FTy->getReturnType()->isPointerTy() || |
| 6590 |
(Call.doesNotReturn() && FTy->getReturnType()->isVoidTy())), |
6590 |
(Call.doesNotReturn() && FTy->getReturnType()->isVoidTy())), |
| 6591 |
"a call with operand bundle \"clang.arc.attachedcall\" must call a " |
6591 |
"a call with operand bundle \"clang.arc.attachedcall\" must call a " |
| 6592 |
"function returning a pointer or a non-returning function that has a " |
6592 |
"function returning a pointer or a non-returning function that has a " |
| 6593 |
"void return type", |
6593 |
"void return type", |
| 6594 |
Call); |
6594 |
Call); |
| 6595 |
|
6595 |
|
| 6596 |
Check(BU.Inputs.size() == 1 && isa(BU.Inputs.front()), |
6596 |
Check(BU.Inputs.size() == 1 && isa(BU.Inputs.front()), |
| 6597 |
"operand bundle \"clang.arc.attachedcall\" requires one function as " |
6597 |
"operand bundle \"clang.arc.attachedcall\" requires one function as " |
| 6598 |
"an argument", |
6598 |
"an argument", |
| 6599 |
Call); |
6599 |
Call); |
| 6600 |
|
6600 |
|
| 6601 |
auto *Fn = cast(BU.Inputs.front()); |
6601 |
auto *Fn = cast(BU.Inputs.front()); |
| 6602 |
Intrinsic::ID IID = Fn->getIntrinsicID(); |
6602 |
Intrinsic::ID IID = Fn->getIntrinsicID(); |
| 6603 |
|
6603 |
|
| 6604 |
if (IID) { |
6604 |
if (IID) { |
| 6605 |
Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue || |
6605 |
Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue || |
| 6606 |
IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue), |
6606 |
IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue), |
| 6607 |
"invalid function argument", Call); |
6607 |
"invalid function argument", Call); |
| 6608 |
} else { |
6608 |
} else { |
| 6609 |
StringRef FnName = Fn->getName(); |
6609 |
StringRef FnName = Fn->getName(); |
| 6610 |
Check((FnName == "objc_retainAutoreleasedReturnValue" || |
6610 |
Check((FnName == "objc_retainAutoreleasedReturnValue" || |
| 6611 |
FnName == "objc_unsafeClaimAutoreleasedReturnValue"), |
6611 |
FnName == "objc_unsafeClaimAutoreleasedReturnValue"), |
| 6612 |
"invalid function argument", Call); |
6612 |
"invalid function argument", Call); |
| 6613 |
} |
6613 |
} |
| 6614 |
} |
6614 |
} |
| 6615 |
|
6615 |
|
| 6616 |
void Verifier::verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F) { |
6616 |
void Verifier::verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F) { |
| 6617 |
bool HasSource = F.getSource().has_value(); |
6617 |
bool HasSource = F.getSource().has_value(); |
| 6618 |
if (!HasSourceDebugInfo.count(&U)) |
6618 |
if (!HasSourceDebugInfo.count(&U)) |
| 6619 |
HasSourceDebugInfo[&U] = HasSource; |
6619 |
HasSourceDebugInfo[&U] = HasSource; |
| 6620 |
CheckDI(HasSource == HasSourceDebugInfo[&U], |
6620 |
CheckDI(HasSource == HasSourceDebugInfo[&U], |
| 6621 |
"inconsistent use of embedded source"); |
6621 |
"inconsistent use of embedded source"); |
| 6622 |
} |
6622 |
} |
| 6623 |
|
6623 |
|
| 6624 |
void Verifier::verifyNoAliasScopeDecl() { |
6624 |
void Verifier::verifyNoAliasScopeDecl() { |
| 6625 |
if (NoAliasScopeDecls.empty()) |
6625 |
if (NoAliasScopeDecls.empty()) |
| 6626 |
return; |
6626 |
return; |
| 6627 |
|
6627 |
|
| 6628 |
// only a single scope must be declared at a time. |
6628 |
// only a single scope must be declared at a time. |
| 6629 |
for (auto *II : NoAliasScopeDecls) { |
6629 |
for (auto *II : NoAliasScopeDecls) { |
| 6630 |
assert(II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl && |
6630 |
assert(II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl && |
| 6631 |
"Not a llvm.experimental.noalias.scope.decl ?"); |
6631 |
"Not a llvm.experimental.noalias.scope.decl ?"); |
| 6632 |
const auto *ScopeListMV = dyn_cast( |
6632 |
const auto *ScopeListMV = dyn_cast( |
| 6633 |
II->getOperand(Intrinsic::NoAliasScopeDeclScopeArg)); |
6633 |
II->getOperand(Intrinsic::NoAliasScopeDeclScopeArg)); |
| 6634 |
Check(ScopeListMV != nullptr, |
6634 |
Check(ScopeListMV != nullptr, |
| 6635 |
"llvm.experimental.noalias.scope.decl must have a MetadataAsValue " |
6635 |
"llvm.experimental.noalias.scope.decl must have a MetadataAsValue " |
| 6636 |
"argument", |
6636 |
"argument", |
| 6637 |
II); |
6637 |
II); |
| 6638 |
|
6638 |
|
| 6639 |
const auto *ScopeListMD = dyn_cast(ScopeListMV->getMetadata()); |
6639 |
const auto *ScopeListMD = dyn_cast(ScopeListMV->getMetadata()); |
| 6640 |
Check(ScopeListMD != nullptr, "!id.scope.list must point to an MDNode", II); |
6640 |
Check(ScopeListMD != nullptr, "!id.scope.list must point to an MDNode", II); |
| 6641 |
Check(ScopeListMD->getNumOperands() == 1, |
6641 |
Check(ScopeListMD->getNumOperands() == 1, |
| 6642 |
"!id.scope.list must point to a list with a single scope", II); |
6642 |
"!id.scope.list must point to a list with a single scope", II); |
| 6643 |
visitAliasScopeListMetadata(ScopeListMD); |
6643 |
visitAliasScopeListMetadata(ScopeListMD); |
| 6644 |
} |
6644 |
} |
| 6645 |
|
6645 |
|
| 6646 |
// Only check the domination rule when requested. Once all passes have been |
6646 |
// Only check the domination rule when requested. Once all passes have been |
| 6647 |
// adapted this option can go away. |
6647 |
// adapted this option can go away. |
| 6648 |
if (!VerifyNoAliasScopeDomination) |
6648 |
if (!VerifyNoAliasScopeDomination) |
| 6649 |
return; |
6649 |
return; |
| 6650 |
|
6650 |
|
| 6651 |
// Now sort the intrinsics based on the scope MDNode so that declarations of |
6651 |
// Now sort the intrinsics based on the scope MDNode so that declarations of |
| 6652 |
// the same scopes are next to each other. |
6652 |
// the same scopes are next to each other. |
| 6653 |
auto GetScope = [](IntrinsicInst *II) { |
6653 |
auto GetScope = [](IntrinsicInst *II) { |
| 6654 |
const auto *ScopeListMV = cast( |
6654 |
const auto *ScopeListMV = cast( |
| 6655 |
II->getOperand(Intrinsic::NoAliasScopeDeclScopeArg)); |
6655 |
II->getOperand(Intrinsic::NoAliasScopeDeclScopeArg)); |
| 6656 |
return &cast(ScopeListMV->getMetadata())->getOperand(0); |
6656 |
return &cast(ScopeListMV->getMetadata())->getOperand(0); |
| 6657 |
}; |
6657 |
}; |
| 6658 |
|
6658 |
|
| 6659 |
// We are sorting on MDNode pointers here. For valid input IR this is ok. |
6659 |
// We are sorting on MDNode pointers here. For valid input IR this is ok. |
| 6660 |
// TODO: Sort on Metadata ID to avoid non-deterministic error messages. |
6660 |
// TODO: Sort on Metadata ID to avoid non-deterministic error messages. |
| 6661 |
auto Compare = [GetScope](IntrinsicInst *Lhs, IntrinsicInst *Rhs) { |
6661 |
auto Compare = [GetScope](IntrinsicInst *Lhs, IntrinsicInst *Rhs) { |
| 6662 |
return GetScope(Lhs) < GetScope(Rhs); |
6662 |
return GetScope(Lhs) < GetScope(Rhs); |
| 6663 |
}; |
6663 |
}; |
| 6664 |
|
6664 |
|
| 6665 |
llvm::sort(NoAliasScopeDecls, Compare); |
6665 |
llvm::sort(NoAliasScopeDecls, Compare); |
| 6666 |
|
6666 |
|
| 6667 |
// Go over the intrinsics and check that for the same scope, they are not |
6667 |
// Go over the intrinsics and check that for the same scope, they are not |
| 6668 |
// dominating each other. |
6668 |
// dominating each other. |
| 6669 |
auto ItCurrent = NoAliasScopeDecls.begin(); |
6669 |
auto ItCurrent = NoAliasScopeDecls.begin(); |
| 6670 |
while (ItCurrent != NoAliasScopeDecls.end()) { |
6670 |
while (ItCurrent != NoAliasScopeDecls.end()) { |
| 6671 |
auto CurScope = GetScope(*ItCurrent); |
6671 |
auto CurScope = GetScope(*ItCurrent); |
| 6672 |
auto ItNext = ItCurrent; |
6672 |
auto ItNext = ItCurrent; |
| 6673 |
do { |
6673 |
do { |
| 6674 |
++ItNext; |
6674 |
++ItNext; |
| 6675 |
} while (ItNext != NoAliasScopeDecls.end() && |
6675 |
} while (ItNext != NoAliasScopeDecls.end() && |
| 6676 |
GetScope(*ItNext) == CurScope); |
6676 |
GetScope(*ItNext) == CurScope); |
| 6677 |
|
6677 |
|
| 6678 |
// [ItCurrent, ItNext) represents the declarations for the same scope. |
6678 |
// [ItCurrent, ItNext) represents the declarations for the same scope. |
| 6679 |
// Ensure they are not dominating each other.. but only if it is not too |
6679 |
// Ensure they are not dominating each other.. but only if it is not too |
| 6680 |
// expensive. |
6680 |
// expensive. |
| 6681 |
if (ItNext - ItCurrent < 32) |
6681 |
if (ItNext - ItCurrent < 32) |
| 6682 |
for (auto *I : llvm::make_range(ItCurrent, ItNext)) |
6682 |
for (auto *I : llvm::make_range(ItCurrent, ItNext)) |
| 6683 |
for (auto *J : llvm::make_range(ItCurrent, ItNext)) |
6683 |
for (auto *J : llvm::make_range(ItCurrent, ItNext)) |
| 6684 |
if (I != J) |
6684 |
if (I != J) |
| 6685 |
Check(!DT.dominates(I, J), |
6685 |
Check(!DT.dominates(I, J), |
| 6686 |
"llvm.experimental.noalias.scope.decl dominates another one " |
6686 |
"llvm.experimental.noalias.scope.decl dominates another one " |
| 6687 |
"with the same scope", |
6687 |
"with the same scope", |
| 6688 |
I); |
6688 |
I); |
| 6689 |
ItCurrent = ItNext; |
6689 |
ItCurrent = ItNext; |
| 6690 |
} |
6690 |
} |
| 6691 |
} |
6691 |
} |
| 6692 |
|
6692 |
|
| 6693 |
//===----------------------------------------------------------------------===// |
6693 |
//===----------------------------------------------------------------------===// |
| 6694 |
// Implement the public interfaces to this file... |
6694 |
// Implement the public interfaces to this file... |
| 6695 |
//===----------------------------------------------------------------------===// |
6695 |
//===----------------------------------------------------------------------===// |
| 6696 |
|
6696 |
|
| 6697 |
bool llvm::verifyFunction(const Function &f, raw_ostream *OS) { |
6697 |
bool llvm::verifyFunction(const Function &f, raw_ostream *OS) { |
| 6698 |
Function &F = const_cast(f); |
6698 |
Function &F = const_cast(f); |
| 6699 |
|
6699 |
|
| 6700 |
// Don't use a raw_null_ostream. Printing IR is expensive. |
6700 |
// Don't use a raw_null_ostream. Printing IR is expensive. |
| 6701 |
Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/true, *f.getParent()); |
6701 |
Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/true, *f.getParent()); |
| 6702 |
|
6702 |
|
| 6703 |
// Note that this function's return value is inverted from what you would |
6703 |
// Note that this function's return value is inverted from what you would |
| 6704 |
// expect of a function called "verify". |
6704 |
// expect of a function called "verify". |
| 6705 |
return !V.verify(F); |
6705 |
return !V.verify(F); |
| 6706 |
} |
6706 |
} |
| 6707 |
|
6707 |
|
| 6708 |
bool llvm::verifyModule(const Module &M, raw_ostream *OS, |
6708 |
bool llvm::verifyModule(const Module &M, raw_ostream *OS, |
| 6709 |
bool *BrokenDebugInfo) { |
6709 |
bool *BrokenDebugInfo) { |
| 6710 |
// Don't use a raw_null_ostream. Printing IR is expensive. |
6710 |
// Don't use a raw_null_ostream. Printing IR is expensive. |
| 6711 |
Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/!BrokenDebugInfo, M); |
6711 |
Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/!BrokenDebugInfo, M); |
| 6712 |
|
6712 |
|
| 6713 |
bool Broken = false; |
6713 |
bool Broken = false; |
| 6714 |
for (const Function &F : M) |
6714 |
for (const Function &F : M) |
| 6715 |
Broken |= !V.verify(F); |
6715 |
Broken |= !V.verify(F); |
| 6716 |
|
6716 |
|
| 6717 |
Broken |= !V.verify(); |
6717 |
Broken |= !V.verify(); |
| 6718 |
if (BrokenDebugInfo) |
6718 |
if (BrokenDebugInfo) |
| 6719 |
*BrokenDebugInfo = V.hasBrokenDebugInfo(); |
6719 |
*BrokenDebugInfo = V.hasBrokenDebugInfo(); |
| 6720 |
// Note that this function's return value is inverted from what you would |
6720 |
// Note that this function's return value is inverted from what you would |
| 6721 |
// expect of a function called "verify". |
6721 |
// expect of a function called "verify". |
| 6722 |
return Broken; |
6722 |
return Broken; |
| 6723 |
} |
6723 |
} |
| 6724 |
|
6724 |
|
| 6725 |
namespace { |
6725 |
namespace { |
| 6726 |
|
6726 |
|
| 6727 |
struct VerifierLegacyPass : public FunctionPass { |
6727 |
struct VerifierLegacyPass : public FunctionPass { |
| 6728 |
static char ID; |
6728 |
static char ID; |
| 6729 |
|
6729 |
|
| 6730 |
std::unique_ptr V; |
6730 |
std::unique_ptr V; |
| 6731 |
bool FatalErrors = true; |
6731 |
bool FatalErrors = true; |
| 6732 |
|
6732 |
|
| 6733 |
VerifierLegacyPass() : FunctionPass(ID) { |
6733 |
VerifierLegacyPass() : FunctionPass(ID) { |
| 6734 |
initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry()); |
6734 |
initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry()); |
| 6735 |
} |
6735 |
} |
| 6736 |
explicit VerifierLegacyPass(bool FatalErrors) |
6736 |
explicit VerifierLegacyPass(bool FatalErrors) |
| 6737 |
: FunctionPass(ID), |
6737 |
: FunctionPass(ID), |
| 6738 |
FatalErrors(FatalErrors) { |
6738 |
FatalErrors(FatalErrors) { |
| 6739 |
initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry()); |
6739 |
initializeVerifierLegacyPassPass(*PassRegistry::getPassRegistry()); |
| 6740 |
} |
6740 |
} |
| 6741 |
|
6741 |
|
| 6742 |
bool doInitialization(Module &M) override { |
6742 |
bool doInitialization(Module &M) override { |
| 6743 |
V = std::make_unique( |
6743 |
V = std::make_unique( |
| 6744 |
&dbgs(), /*ShouldTreatBrokenDebugInfoAsError=*/false, M); |
6744 |
&dbgs(), /*ShouldTreatBrokenDebugInfoAsError=*/false, M); |
| 6745 |
return false; |
6745 |
return false; |
| 6746 |
} |
6746 |
} |
| 6747 |
|
6747 |
|
| 6748 |
bool runOnFunction(Function &F) override { |
6748 |
bool runOnFunction(Function &F) override { |
| 6749 |
if (!V->verify(F) && FatalErrors) { |
6749 |
if (!V->verify(F) && FatalErrors) { |
| 6750 |
errs() << "in function " << F.getName() << '\n'; |
6750 |
errs() << "in function " << F.getName() << '\n'; |
| 6751 |
report_fatal_error("Broken function found, compilation aborted!"); |
6751 |
report_fatal_error("Broken function found, compilation aborted!"); |
| 6752 |
} |
6752 |
} |
| 6753 |
return false; |
6753 |
return false; |
| 6754 |
} |
6754 |
} |
| 6755 |
|
6755 |
|
| 6756 |
bool doFinalization(Module &M) override { |
6756 |
bool doFinalization(Module &M) override { |
| 6757 |
bool HasErrors = false; |
6757 |
bool HasErrors = false; |
| 6758 |
for (Function &F : M) |
6758 |
for (Function &F : M) |
| 6759 |
if (F.isDeclaration()) |
6759 |
if (F.isDeclaration()) |
| 6760 |
HasErrors |= !V->verify(F); |
6760 |
HasErrors |= !V->verify(F); |
| 6761 |
|
6761 |
|
| 6762 |
HasErrors |= !V->verify(); |
6762 |
HasErrors |= !V->verify(); |
| 6763 |
if (FatalErrors && (HasErrors || V->hasBrokenDebugInfo())) |
6763 |
if (FatalErrors && (HasErrors || V->hasBrokenDebugInfo())) |
| 6764 |
report_fatal_error("Broken module found, compilation aborted!"); |
6764 |
report_fatal_error("Broken module found, compilation aborted!"); |
| 6765 |
return false; |
6765 |
return false; |
| 6766 |
} |
6766 |
} |
| 6767 |
|
6767 |
|
| 6768 |
void getAnalysisUsage(AnalysisUsage &AU) const override { |
6768 |
void getAnalysisUsage(AnalysisUsage &AU) const override { |
| 6769 |
AU.setPreservesAll(); |
6769 |
AU.setPreservesAll(); |
| 6770 |
} |
6770 |
} |
| 6771 |
}; |
6771 |
}; |
| 6772 |
|
6772 |
|
| 6773 |
} // end anonymous namespace |
6773 |
} // end anonymous namespace |
| 6774 |
|
6774 |
|
| 6775 |
/// Helper to issue failure from the TBAA verification |
6775 |
/// Helper to issue failure from the TBAA verification |
| 6776 |
template void TBAAVerifier::CheckFailed(Tys &&... Args) { |
6776 |
template void TBAAVerifier::CheckFailed(Tys &&... Args) { |
| 6777 |
if (Diagnostic) |
6777 |
if (Diagnostic) |
| 6778 |
return Diagnostic->CheckFailed(Args...); |
6778 |
return Diagnostic->CheckFailed(Args...); |
| 6779 |
} |
6779 |
} |
| 6780 |
|
6780 |
|
| 6781 |
#define CheckTBAA(C, ...) \ |
6781 |
#define CheckTBAA(C, ...) \ |
| 6782 |
do { \ |
6782 |
do { \ |
| 6783 |
if (!(C)) { \ |
6783 |
if (!(C)) { \ |
| 6784 |
CheckFailed(__VA_ARGS__); \ |
6784 |
CheckFailed(__VA_ARGS__); \ |
| 6785 |
return false; \ |
6785 |
return false; \ |
| 6786 |
} \ |
6786 |
} \ |
| 6787 |
} while (false) |
6787 |
} while (false) |
| 6788 |
|
6788 |
|
| 6789 |
/// Verify that \p BaseNode can be used as the "base type" in the struct-path |
6789 |
/// Verify that \p BaseNode can be used as the "base type" in the struct-path |
| 6790 |
/// TBAA scheme. This means \p BaseNode is either a scalar node, or a |
6790 |
/// TBAA scheme. This means \p BaseNode is either a scalar node, or a |
| 6791 |
/// struct-type node describing an aggregate data structure (like a struct). |
6791 |
/// struct-type node describing an aggregate data structure (like a struct). |
| 6792 |
TBAAVerifier::TBAABaseNodeSummary |
6792 |
TBAAVerifier::TBAABaseNodeSummary |
| 6793 |
TBAAVerifier::verifyTBAABaseNode(Instruction &I, const MDNode *BaseNode, |
6793 |
TBAAVerifier::verifyTBAABaseNode(Instruction &I, const MDNode *BaseNode, |
| 6794 |
bool IsNewFormat) { |
6794 |
bool IsNewFormat) { |
| 6795 |
if (BaseNode->getNumOperands() < 2) { |
6795 |
if (BaseNode->getNumOperands() < 2) { |
| 6796 |
CheckFailed("Base nodes must have at least two operands", &I, BaseNode); |
6796 |
CheckFailed("Base nodes must have at least two operands", &I, BaseNode); |
| 6797 |
return {true, ~0u}; |
6797 |
return {true, ~0u}; |
| 6798 |
} |
6798 |
} |
| 6799 |
|
6799 |
|
| 6800 |
auto Itr = TBAABaseNodes.find(BaseNode); |
6800 |
auto Itr = TBAABaseNodes.find(BaseNode); |
| 6801 |
if (Itr != TBAABaseNodes.end()) |
6801 |
if (Itr != TBAABaseNodes.end()) |
| 6802 |
return Itr->second; |
6802 |
return Itr->second; |
| 6803 |
|
6803 |
|
| 6804 |
auto Result = verifyTBAABaseNodeImpl(I, BaseNode, IsNewFormat); |
6804 |
auto Result = verifyTBAABaseNodeImpl(I, BaseNode, IsNewFormat); |
| 6805 |
auto InsertResult = TBAABaseNodes.insert({BaseNode, Result}); |
6805 |
auto InsertResult = TBAABaseNodes.insert({BaseNode, Result}); |
| 6806 |
(void)InsertResult; |
6806 |
(void)InsertResult; |
| 6807 |
assert(InsertResult.second && "We just checked!"); |
6807 |
assert(InsertResult.second && "We just checked!"); |
| 6808 |
return Result; |
6808 |
return Result; |
| 6809 |
} |
6809 |
} |
| 6810 |
|
6810 |
|
| 6811 |
TBAAVerifier::TBAABaseNodeSummary |
6811 |
TBAAVerifier::TBAABaseNodeSummary |
| 6812 |
TBAAVerifier::verifyTBAABaseNodeImpl(Instruction &I, const MDNode *BaseNode, |
6812 |
TBAAVerifier::verifyTBAABaseNodeImpl(Instruction &I, const MDNode *BaseNode, |
| 6813 |
bool IsNewFormat) { |
6813 |
bool IsNewFormat) { |
| 6814 |
const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {true, ~0u}; |
6814 |
const TBAAVerifier::TBAABaseNodeSummary InvalidNode = {true, ~0u}; |
| 6815 |
|
6815 |
|
| 6816 |
if (BaseNode->getNumOperands() == 2) { |
6816 |
if (BaseNode->getNumOperands() == 2) { |
| 6817 |
// Scalar nodes can only be accessed at offset 0. |
6817 |
// Scalar nodes can only be accessed at offset 0. |
| 6818 |
return isValidScalarTBAANode(BaseNode) |
6818 |
return isValidScalarTBAANode(BaseNode) |
| 6819 |
? TBAAVerifier::TBAABaseNodeSummary({false, 0}) |
6819 |
? TBAAVerifier::TBAABaseNodeSummary({false, 0}) |
| 6820 |
: InvalidNode; |
6820 |
: InvalidNode; |
| 6821 |
} |
6821 |
} |
| 6822 |
|
6822 |
|
| 6823 |
if (IsNewFormat) { |
6823 |
if (IsNewFormat) { |
| 6824 |
if (BaseNode->getNumOperands() % 3 != 0) { |
6824 |
if (BaseNode->getNumOperands() % 3 != 0) { |
| 6825 |
CheckFailed("Access tag nodes must have the number of operands that is a " |
6825 |
CheckFailed("Access tag nodes must have the number of operands that is a " |
| 6826 |
"multiple of 3!", BaseNode); |
6826 |
"multiple of 3!", BaseNode); |
| 6827 |
return InvalidNode; |
6827 |
return InvalidNode; |
| 6828 |
} |
6828 |
} |
| 6829 |
} else { |
6829 |
} else { |
| 6830 |
if (BaseNode->getNumOperands() % 2 != 1) { |
6830 |
if (BaseNode->getNumOperands() % 2 != 1) { |
| 6831 |
CheckFailed("Struct tag nodes must have an odd number of operands!", |
6831 |
CheckFailed("Struct tag nodes must have an odd number of operands!", |
| 6832 |
BaseNode); |
6832 |
BaseNode); |
| 6833 |
return InvalidNode; |
6833 |
return InvalidNode; |
| 6834 |
} |
6834 |
} |
| 6835 |
} |
6835 |
} |
| 6836 |
|
6836 |
|
| 6837 |
// Check the type size field. |
6837 |
// Check the type size field. |
| 6838 |
if (IsNewFormat) { |
6838 |
if (IsNewFormat) { |
| 6839 |
auto *TypeSizeNode = mdconst::dyn_extract_or_null( |
6839 |
auto *TypeSizeNode = mdconst::dyn_extract_or_null( |
| 6840 |
BaseNode->getOperand(1)); |
6840 |
BaseNode->getOperand(1)); |
| 6841 |
if (!TypeSizeNode) { |
6841 |
if (!TypeSizeNode) { |
| 6842 |
CheckFailed("Type size nodes must be constants!", &I, BaseNode); |
6842 |
CheckFailed("Type size nodes must be constants!", &I, BaseNode); |
| 6843 |
return InvalidNode; |
6843 |
return InvalidNode; |
| 6844 |
} |
6844 |
} |
| 6845 |
} |
6845 |
} |
| 6846 |
|
6846 |
|
| 6847 |
// Check the type name field. In the new format it can be anything. |
6847 |
// Check the type name field. In the new format it can be anything. |
| 6848 |
if (!IsNewFormat && !isa(BaseNode->getOperand(0))) { |
6848 |
if (!IsNewFormat && !isa(BaseNode->getOperand(0))) { |
| 6849 |
CheckFailed("Struct tag nodes have a string as their first operand", |
6849 |
CheckFailed("Struct tag nodes have a string as their first operand", |
| 6850 |
BaseNode); |
6850 |
BaseNode); |
| 6851 |
return InvalidNode; |
6851 |
return InvalidNode; |
| 6852 |
} |
6852 |
} |
| 6853 |
|
6853 |
|
| 6854 |
bool Failed = false; |
6854 |
bool Failed = false; |
| 6855 |
|
6855 |
|
| 6856 |
std::optional PrevOffset; |
6856 |
std::optional PrevOffset; |
| 6857 |
unsigned BitWidth = ~0u; |
6857 |
unsigned BitWidth = ~0u; |
| 6858 |
|
6858 |
|
| 6859 |
// We've already checked that BaseNode is not a degenerate root node with one |
6859 |
// We've already checked that BaseNode is not a degenerate root node with one |
| 6860 |
// operand in \c verifyTBAABaseNode, so this loop should run at least once. |
6860 |
// operand in \c verifyTBAABaseNode, so this loop should run at least once. |
| 6861 |
unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1; |
6861 |
unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1; |
| 6862 |
unsigned NumOpsPerField = IsNewFormat ? 3 : 2; |
6862 |
unsigned NumOpsPerField = IsNewFormat ? 3 : 2; |
| 6863 |
for (unsigned Idx = FirstFieldOpNo; Idx < BaseNode->getNumOperands(); |
6863 |
for (unsigned Idx = FirstFieldOpNo; Idx < BaseNode->getNumOperands(); |
| 6864 |
Idx += NumOpsPerField) { |
6864 |
Idx += NumOpsPerField) { |
| 6865 |
const MDOperand &FieldTy = BaseNode->getOperand(Idx); |
6865 |
const MDOperand &FieldTy = BaseNode->getOperand(Idx); |
| 6866 |
const MDOperand &FieldOffset = BaseNode->getOperand(Idx + 1); |
6866 |
const MDOperand &FieldOffset = BaseNode->getOperand(Idx + 1); |
| 6867 |
if (!isa(FieldTy)) { |
6867 |
if (!isa(FieldTy)) { |
| 6868 |
CheckFailed("Incorrect field entry in struct type node!", &I, BaseNode); |
6868 |
CheckFailed("Incorrect field entry in struct type node!", &I, BaseNode); |
| 6869 |
Failed = true; |
6869 |
Failed = true; |
| 6870 |
continue; |
6870 |
continue; |
| 6871 |
} |
6871 |
} |
| 6872 |
|
6872 |
|
| 6873 |
auto *OffsetEntryCI = |
6873 |
auto *OffsetEntryCI = |
| 6874 |
mdconst::dyn_extract_or_null(FieldOffset); |
6874 |
mdconst::dyn_extract_or_null(FieldOffset); |
| 6875 |
if (!OffsetEntryCI) { |
6875 |
if (!OffsetEntryCI) { |
| 6876 |
CheckFailed("Offset entries must be constants!", &I, BaseNode); |
6876 |
CheckFailed("Offset entries must be constants!", &I, BaseNode); |
| 6877 |
Failed = true; |
6877 |
Failed = true; |
| 6878 |
continue; |
6878 |
continue; |
| 6879 |
} |
6879 |
} |
| 6880 |
|
6880 |
|
| 6881 |
if (BitWidth == ~0u) |
6881 |
if (BitWidth == ~0u) |
| 6882 |
BitWidth = OffsetEntryCI->getBitWidth(); |
6882 |
BitWidth = OffsetEntryCI->getBitWidth(); |
| 6883 |
|
6883 |
|
| 6884 |
if (OffsetEntryCI->getBitWidth() != BitWidth) { |
6884 |
if (OffsetEntryCI->getBitWidth() != BitWidth) { |
| 6885 |
CheckFailed( |
6885 |
CheckFailed( |
| 6886 |
"Bitwidth between the offsets and struct type entries must match", &I, |
6886 |
"Bitwidth between the offsets and struct type entries must match", &I, |
| 6887 |
BaseNode); |
6887 |
BaseNode); |
| 6888 |
Failed = true; |
6888 |
Failed = true; |
| 6889 |
continue; |
6889 |
continue; |
| 6890 |
} |
6890 |
} |
| 6891 |
|
6891 |
|
| 6892 |
// NB! As far as I can tell, we generate a non-strictly increasing offset |
6892 |
// NB! As far as I can tell, we generate a non-strictly increasing offset |
| 6893 |
// sequence only from structs that have zero size bit fields. When |
6893 |
// sequence only from structs that have zero size bit fields. When |
| 6894 |
// recursing into a contained struct in \c getFieldNodeFromTBAABaseNode we |
6894 |
// recursing into a contained struct in \c getFieldNodeFromTBAABaseNode we |
| 6895 |
// pick the field lexically the latest in struct type metadata node. This |
6895 |
// pick the field lexically the latest in struct type metadata node. This |
| 6896 |
// mirrors the actual behavior of the alias analysis implementation. |
6896 |
// mirrors the actual behavior of the alias analysis implementation. |
| 6897 |
bool IsAscending = |
6897 |
bool IsAscending = |
| 6898 |
!PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue()); |
6898 |
!PrevOffset || PrevOffset->ule(OffsetEntryCI->getValue()); |
| 6899 |
|
6899 |
|
| 6900 |
if (!IsAscending) { |
6900 |
if (!IsAscending) { |
| 6901 |
CheckFailed("Offsets must be increasing!", &I, BaseNode); |
6901 |
CheckFailed("Offsets must be increasing!", &I, BaseNode); |
| 6902 |
Failed = true; |
6902 |
Failed = true; |
| 6903 |
} |
6903 |
} |
| 6904 |
|
6904 |
|
| 6905 |
PrevOffset = OffsetEntryCI->getValue(); |
6905 |
PrevOffset = OffsetEntryCI->getValue(); |
| 6906 |
|
6906 |
|
| 6907 |
if (IsNewFormat) { |
6907 |
if (IsNewFormat) { |
| 6908 |
auto *MemberSizeNode = mdconst::dyn_extract_or_null( |
6908 |
auto *MemberSizeNode = mdconst::dyn_extract_or_null( |
| 6909 |
BaseNode->getOperand(Idx + 2)); |
6909 |
BaseNode->getOperand(Idx + 2)); |
| 6910 |
if (!MemberSizeNode) { |
6910 |
if (!MemberSizeNode) { |
| 6911 |
CheckFailed("Member size entries must be constants!", &I, BaseNode); |
6911 |
CheckFailed("Member size entries must be constants!", &I, BaseNode); |
| 6912 |
Failed = true; |
6912 |
Failed = true; |
| 6913 |
continue; |
6913 |
continue; |
| 6914 |
} |
6914 |
} |
| 6915 |
} |
6915 |
} |
| 6916 |
} |
6916 |
} |
| 6917 |
|
6917 |
|
| 6918 |
return Failed ? InvalidNode |
6918 |
return Failed ? InvalidNode |
| 6919 |
: TBAAVerifier::TBAABaseNodeSummary(false, BitWidth); |
6919 |
: TBAAVerifier::TBAABaseNodeSummary(false, BitWidth); |
| 6920 |
} |
6920 |
} |
| 6921 |
|
6921 |
|
| 6922 |
static bool IsRootTBAANode(const MDNode *MD) { |
6922 |
static bool IsRootTBAANode(const MDNode *MD) { |
| 6923 |
return MD->getNumOperands() < 2; |
6923 |
return MD->getNumOperands() < 2; |
| 6924 |
} |
6924 |
} |
| 6925 |
|
6925 |
|
| 6926 |
static bool IsScalarTBAANodeImpl(const MDNode *MD, |
6926 |
static bool IsScalarTBAANodeImpl(const MDNode *MD, |
| 6927 |
SmallPtrSetImpl &Visited) { |
6927 |
SmallPtrSetImpl &Visited) { |
| 6928 |
if (MD->getNumOperands() != 2 && MD->getNumOperands() != 3) |
6928 |
if (MD->getNumOperands() != 2 && MD->getNumOperands() != 3) |
| 6929 |
return false; |
6929 |
return false; |
| 6930 |
|
6930 |
|
| 6931 |
if (!isa(MD->getOperand(0))) |
6931 |
if (!isa(MD->getOperand(0))) |
| 6932 |
return false; |
6932 |
return false; |
| 6933 |
|
6933 |
|
| 6934 |
if (MD->getNumOperands() == 3) { |
6934 |
if (MD->getNumOperands() == 3) { |
| 6935 |
auto *Offset = mdconst::dyn_extract(MD->getOperand(2)); |
6935 |
auto *Offset = mdconst::dyn_extract(MD->getOperand(2)); |
| 6936 |
if (!(Offset && Offset->isZero() && isa(MD->getOperand(0)))) |
6936 |
if (!(Offset && Offset->isZero() && isa(MD->getOperand(0)))) |
| 6937 |
return false; |
6937 |
return false; |
| 6938 |
} |
6938 |
} |
| 6939 |
|
6939 |
|
| 6940 |
auto *Parent = dyn_cast_or_null(MD->getOperand(1)); |
6940 |
auto *Parent = dyn_cast_or_null(MD->getOperand(1)); |
| 6941 |
return Parent && Visited.insert(Parent).second && |
6941 |
return Parent && Visited.insert(Parent).second && |
| 6942 |
(IsRootTBAANode(Parent) || IsScalarTBAANodeImpl(Parent, Visited)); |
6942 |
(IsRootTBAANode(Parent) || IsScalarTBAANodeImpl(Parent, Visited)); |
| 6943 |
} |
6943 |
} |
| 6944 |
|
6944 |
|
| 6945 |
bool TBAAVerifier::isValidScalarTBAANode(const MDNode *MD) { |
6945 |
bool TBAAVerifier::isValidScalarTBAANode(const MDNode *MD) { |
| 6946 |
auto ResultIt = TBAAScalarNodes.find(MD); |
6946 |
auto ResultIt = TBAAScalarNodes.find(MD); |
| 6947 |
if (ResultIt != TBAAScalarNodes.end()) |
6947 |
if (ResultIt != TBAAScalarNodes.end()) |
| 6948 |
return ResultIt->second; |
6948 |
return ResultIt->second; |
| 6949 |
|
6949 |
|
| 6950 |
SmallPtrSet Visited; |
6950 |
SmallPtrSet Visited; |
| 6951 |
bool Result = IsScalarTBAANodeImpl(MD, Visited); |
6951 |
bool Result = IsScalarTBAANodeImpl(MD, Visited); |
| 6952 |
auto InsertResult = TBAAScalarNodes.insert({MD, Result}); |
6952 |
auto InsertResult = TBAAScalarNodes.insert({MD, Result}); |
| 6953 |
(void)InsertResult; |
6953 |
(void)InsertResult; |
| 6954 |
assert(InsertResult.second && "Just checked!"); |
6954 |
assert(InsertResult.second && "Just checked!"); |
| 6955 |
|
6955 |
|
| 6956 |
return Result; |
6956 |
return Result; |
| 6957 |
} |
6957 |
} |
| 6958 |
|
6958 |
|
| 6959 |
/// Returns the field node at the offset \p Offset in \p BaseNode. Update \p |
6959 |
/// Returns the field node at the offset \p Offset in \p BaseNode. Update \p |
| 6960 |
/// Offset in place to be the offset within the field node returned. |
6960 |
/// Offset in place to be the offset within the field node returned. |
| 6961 |
/// |
6961 |
/// |
| 6962 |
/// We assume we've okayed \p BaseNode via \c verifyTBAABaseNode. |
6962 |
/// We assume we've okayed \p BaseNode via \c verifyTBAABaseNode. |
| 6963 |
MDNode *TBAAVerifier::getFieldNodeFromTBAABaseNode(Instruction &I, |
6963 |
MDNode *TBAAVerifier::getFieldNodeFromTBAABaseNode(Instruction &I, |
| 6964 |
const MDNode *BaseNode, |
6964 |
const MDNode *BaseNode, |
| 6965 |
APInt &Offset, |
6965 |
APInt &Offset, |
| 6966 |
bool IsNewFormat) { |
6966 |
bool IsNewFormat) { |
| 6967 |
assert(BaseNode->getNumOperands() >= 2 && "Invalid base node!"); |
6967 |
assert(BaseNode->getNumOperands() >= 2 && "Invalid base node!"); |
| 6968 |
|
6968 |
|
| 6969 |
// Scalar nodes have only one possible "field" -- their parent in the access |
6969 |
// Scalar nodes have only one possible "field" -- their parent in the access |
| 6970 |
// hierarchy. Offset must be zero at this point, but our caller is supposed |
6970 |
// hierarchy. Offset must be zero at this point, but our caller is supposed |
| 6971 |
// to check that. |
6971 |
// to check that. |
| 6972 |
if (BaseNode->getNumOperands() == 2) |
6972 |
if (BaseNode->getNumOperands() == 2) |
| 6973 |
return cast(BaseNode->getOperand(1)); |
6973 |
return cast(BaseNode->getOperand(1)); |
| 6974 |
|
6974 |
|
| 6975 |
unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1; |
6975 |
unsigned FirstFieldOpNo = IsNewFormat ? 3 : 1; |
| 6976 |
unsigned NumOpsPerField = IsNewFormat ? 3 : 2; |
6976 |
unsigned NumOpsPerField = IsNewFormat ? 3 : 2; |
| 6977 |
for (unsigned Idx = FirstFieldOpNo; Idx < BaseNode->getNumOperands(); |
6977 |
for (unsigned Idx = FirstFieldOpNo; Idx < BaseNode->getNumOperands(); |
| 6978 |
Idx += NumOpsPerField) { |
6978 |
Idx += NumOpsPerField) { |
| 6979 |
auto *OffsetEntryCI = |
6979 |
auto *OffsetEntryCI = |
| 6980 |
mdconst::extract(BaseNode->getOperand(Idx + 1)); |
6980 |
mdconst::extract(BaseNode->getOperand(Idx + 1)); |
| 6981 |
if (OffsetEntryCI->getValue().ugt(Offset)) { |
6981 |
if (OffsetEntryCI->getValue().ugt(Offset)) { |
| 6982 |
if (Idx == FirstFieldOpNo) { |
6982 |
if (Idx == FirstFieldOpNo) { |
| 6983 |
CheckFailed("Could not find TBAA parent in struct type node", &I, |
6983 |
CheckFailed("Could not find TBAA parent in struct type node", &I, |
| 6984 |
BaseNode, &Offset); |
6984 |
BaseNode, &Offset); |
| 6985 |
return nullptr; |
6985 |
return nullptr; |
| 6986 |
} |
6986 |
} |
| 6987 |
|
6987 |
|
| 6988 |
unsigned PrevIdx = Idx - NumOpsPerField; |
6988 |
unsigned PrevIdx = Idx - NumOpsPerField; |
| 6989 |
auto *PrevOffsetEntryCI = |
6989 |
auto *PrevOffsetEntryCI = |
| 6990 |
mdconst::extract(BaseNode->getOperand(PrevIdx + 1)); |
6990 |
mdconst::extract(BaseNode->getOperand(PrevIdx + 1)); |
| 6991 |
Offset -= PrevOffsetEntryCI->getValue(); |
6991 |
Offset -= PrevOffsetEntryCI->getValue(); |
| 6992 |
return cast(BaseNode->getOperand(PrevIdx)); |
6992 |
return cast(BaseNode->getOperand(PrevIdx)); |
| 6993 |
} |
6993 |
} |
| 6994 |
} |
6994 |
} |
| 6995 |
|
6995 |
|
| 6996 |
unsigned LastIdx = BaseNode->getNumOperands() - NumOpsPerField; |
6996 |
unsigned LastIdx = BaseNode->getNumOperands() - NumOpsPerField; |
| 6997 |
auto *LastOffsetEntryCI = mdconst::extract( |
6997 |
auto *LastOffsetEntryCI = mdconst::extract( |
| 6998 |
BaseNode->getOperand(LastIdx + 1)); |
6998 |
BaseNode->getOperand(LastIdx + 1)); |
| 6999 |
Offset -= LastOffsetEntryCI->getValue(); |
6999 |
Offset -= LastOffsetEntryCI->getValue(); |
| 7000 |
return cast(BaseNode->getOperand(LastIdx)); |
7000 |
return cast(BaseNode->getOperand(LastIdx)); |
| 7001 |
} |
7001 |
} |
| 7002 |
|
7002 |
|
| 7003 |
static bool isNewFormatTBAATypeNode(llvm::MDNode *Type) { |
7003 |
static bool isNewFormatTBAATypeNode(llvm::MDNode *Type) { |
| 7004 |
if (!Type || Type->getNumOperands() < 3) |
7004 |
if (!Type || Type->getNumOperands() < 3) |
| 7005 |
return false; |
7005 |
return false; |
| 7006 |
|
7006 |
|
| 7007 |
// In the new format type nodes shall have a reference to the parent type as |
7007 |
// In the new format type nodes shall have a reference to the parent type as |
| 7008 |
// its first operand. |
7008 |
// its first operand. |
| 7009 |
return isa_and_nonnull(Type->getOperand(0)); |
7009 |
return isa_and_nonnull(Type->getOperand(0)); |
| 7010 |
} |
7010 |
} |
| 7011 |
|
7011 |
|
| 7012 |
bool TBAAVerifier::visitTBAAMetadata(Instruction &I, const MDNode *MD) { |
7012 |
bool TBAAVerifier::visitTBAAMetadata(Instruction &I, const MDNode *MD) { |
| 7013 |
CheckTBAA(MD->getNumOperands() > 0, "TBAA metadata cannot have 0 operands", |
7013 |
CheckTBAA(MD->getNumOperands() > 0, "TBAA metadata cannot have 0 operands", |
| 7014 |
&I, MD); |
7014 |
&I, MD); |
| 7015 |
|
7015 |
|
| 7016 |
CheckTBAA(isa(I) || isa(I) || isa(I) || |
7016 |
CheckTBAA(isa(I) || isa(I) || isa(I) || |
| 7017 |
isa(I) || isa(I) || |
7017 |
isa(I) || isa(I) || |
| 7018 |
isa(I), |
7018 |
isa(I), |
| 7019 |
"This instruction shall not have a TBAA access tag!", &I); |
7019 |
"This instruction shall not have a TBAA access tag!", &I); |
| 7020 |
|
7020 |
|
| 7021 |
bool IsStructPathTBAA = |
7021 |
bool IsStructPathTBAA = |
| 7022 |
isa(MD->getOperand(0)) && MD->getNumOperands() >= 3; |
7022 |
isa(MD->getOperand(0)) && MD->getNumOperands() >= 3; |
| 7023 |
|
7023 |
|
| 7024 |
CheckTBAA(IsStructPathTBAA, |
7024 |
CheckTBAA(IsStructPathTBAA, |
| 7025 |
"Old-style TBAA is no longer allowed, use struct-path TBAA instead", |
7025 |
"Old-style TBAA is no longer allowed, use struct-path TBAA instead", |
| 7026 |
&I); |
7026 |
&I); |
| 7027 |
|
7027 |
|
| 7028 |
MDNode *BaseNode = dyn_cast_or_null(MD->getOperand(0)); |
7028 |
MDNode *BaseNode = dyn_cast_or_null(MD->getOperand(0)); |
| 7029 |
MDNode *AccessType = dyn_cast_or_null(MD->getOperand(1)); |
7029 |
MDNode *AccessType = dyn_cast_or_null(MD->getOperand(1)); |
| 7030 |
|
7030 |
|
| 7031 |
bool IsNewFormat = isNewFormatTBAATypeNode(AccessType); |
7031 |
bool IsNewFormat = isNewFormatTBAATypeNode(AccessType); |
| 7032 |
|
7032 |
|
| 7033 |
if (IsNewFormat) { |
7033 |
if (IsNewFormat) { |
| 7034 |
CheckTBAA(MD->getNumOperands() == 4 || MD->getNumOperands() == 5, |
7034 |
CheckTBAA(MD->getNumOperands() == 4 || MD->getNumOperands() == 5, |
| 7035 |
"Access tag metadata must have either 4 or 5 operands", &I, MD); |
7035 |
"Access tag metadata must have either 4 or 5 operands", &I, MD); |
| 7036 |
} else { |
7036 |
} else { |
| 7037 |
CheckTBAA(MD->getNumOperands() < 5, |
7037 |
CheckTBAA(MD->getNumOperands() < 5, |
| 7038 |
"Struct tag metadata must have either 3 or 4 operands", &I, MD); |
7038 |
"Struct tag metadata must have either 3 or 4 operands", &I, MD); |
| 7039 |
} |
7039 |
} |
| 7040 |
|
7040 |
|
| 7041 |
// Check the access size field. |
7041 |
// Check the access size field. |
| 7042 |
if (IsNewFormat) { |
7042 |
if (IsNewFormat) { |
| 7043 |
auto *AccessSizeNode = mdconst::dyn_extract_or_null( |
7043 |
auto *AccessSizeNode = mdconst::dyn_extract_or_null( |
| 7044 |
MD->getOperand(3)); |
7044 |
MD->getOperand(3)); |
| 7045 |
CheckTBAA(AccessSizeNode, "Access size field must be a constant", &I, MD); |
7045 |
CheckTBAA(AccessSizeNode, "Access size field must be a constant", &I, MD); |
| 7046 |
} |
7046 |
} |
| 7047 |
|
7047 |
|
| 7048 |
// Check the immutability flag. |
7048 |
// Check the immutability flag. |
| 7049 |
unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3; |
7049 |
unsigned ImmutabilityFlagOpNo = IsNewFormat ? 4 : 3; |
| 7050 |
if (MD->getNumOperands() == ImmutabilityFlagOpNo + 1) { |
7050 |
if (MD->getNumOperands() == ImmutabilityFlagOpNo + 1) { |
| 7051 |
auto *IsImmutableCI = mdconst::dyn_extract_or_null( |
7051 |
auto *IsImmutableCI = mdconst::dyn_extract_or_null( |
| 7052 |
MD->getOperand(ImmutabilityFlagOpNo)); |
7052 |
MD->getOperand(ImmutabilityFlagOpNo)); |
| 7053 |
CheckTBAA(IsImmutableCI, |
7053 |
CheckTBAA(IsImmutableCI, |
| 7054 |
"Immutability tag on struct tag metadata must be a constant", &I, |
7054 |
"Immutability tag on struct tag metadata must be a constant", &I, |
| 7055 |
MD); |
7055 |
MD); |
| 7056 |
CheckTBAA( |
7056 |
CheckTBAA( |
| 7057 |
IsImmutableCI->isZero() || IsImmutableCI->isOne(), |
7057 |
IsImmutableCI->isZero() || IsImmutableCI->isOne(), |
| 7058 |
"Immutability part of the struct tag metadata must be either 0 or 1", |
7058 |
"Immutability part of the struct tag metadata must be either 0 or 1", |
| 7059 |
&I, MD); |
7059 |
&I, MD); |
| 7060 |
} |
7060 |
} |
| 7061 |
|
7061 |
|
| 7062 |
CheckTBAA(BaseNode && AccessType, |
7062 |
CheckTBAA(BaseNode && AccessType, |
| 7063 |
"Malformed struct tag metadata: base and access-type " |
7063 |
"Malformed struct tag metadata: base and access-type " |
| 7064 |
"should be non-null and point to Metadata nodes", |
7064 |
"should be non-null and point to Metadata nodes", |
| 7065 |
&I, MD, BaseNode, AccessType); |
7065 |
&I, MD, BaseNode, AccessType); |
| 7066 |
|
7066 |
|
| 7067 |
if (!IsNewFormat) { |
7067 |
if (!IsNewFormat) { |
| 7068 |
CheckTBAA(isValidScalarTBAANode(AccessType), |
7068 |
CheckTBAA(isValidScalarTBAANode(AccessType), |
| 7069 |
"Access type node must be a valid scalar type", &I, MD, |
7069 |
"Access type node must be a valid scalar type", &I, MD, |
| 7070 |
AccessType); |
7070 |
AccessType); |
| 7071 |
} |
7071 |
} |
| 7072 |
|
7072 |
|
| 7073 |
auto *OffsetCI = mdconst::dyn_extract_or_null(MD->getOperand(2)); |
7073 |
auto *OffsetCI = mdconst::dyn_extract_or_null(MD->getOperand(2)); |
| 7074 |
CheckTBAA(OffsetCI, "Offset must be constant integer", &I, MD); |
7074 |
CheckTBAA(OffsetCI, "Offset must be constant integer", &I, MD); |
| 7075 |
|
7075 |
|
| 7076 |
APInt Offset = OffsetCI->getValue(); |
7076 |
APInt Offset = OffsetCI->getValue(); |
| 7077 |
bool SeenAccessTypeInPath = false; |
7077 |
bool SeenAccessTypeInPath = false; |
| 7078 |
|
7078 |
|
| 7079 |
SmallPtrSet StructPath; |
7079 |
SmallPtrSet StructPath; |
| 7080 |
|
7080 |
|
| 7081 |
for (/* empty */; BaseNode && !IsRootTBAANode(BaseNode); |
7081 |
for (/* empty */; BaseNode && !IsRootTBAANode(BaseNode); |
| 7082 |
BaseNode = getFieldNodeFromTBAABaseNode(I, BaseNode, Offset, |
7082 |
BaseNode = getFieldNodeFromTBAABaseNode(I, BaseNode, Offset, |
| 7083 |
IsNewFormat)) { |
7083 |
IsNewFormat)) { |
| 7084 |
if (!StructPath.insert(BaseNode).second) { |
7084 |
if (!StructPath.insert(BaseNode).second) { |
| 7085 |
CheckFailed("Cycle detected in struct path", &I, MD); |
7085 |
CheckFailed("Cycle detected in struct path", &I, MD); |
| 7086 |
return false; |
7086 |
return false; |
| 7087 |
} |
7087 |
} |
| 7088 |
|
7088 |
|
| 7089 |
bool Invalid; |
7089 |
bool Invalid; |
| 7090 |
unsigned BaseNodeBitWidth; |
7090 |
unsigned BaseNodeBitWidth; |
| 7091 |
std::tie(Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(I, BaseNode, |
7091 |
std::tie(Invalid, BaseNodeBitWidth) = verifyTBAABaseNode(I, BaseNode, |
| 7092 |
IsNewFormat); |
7092 |
IsNewFormat); |
| 7093 |
|
7093 |
|
| 7094 |
// If the base node is invalid in itself, then we've already printed all the |
7094 |
// If the base node is invalid in itself, then we've already printed all the |
| 7095 |
// errors we wanted to print. |
7095 |
// errors we wanted to print. |
| 7096 |
if (Invalid) |
7096 |
if (Invalid) |
| 7097 |
return false; |
7097 |
return false; |
| 7098 |
|
7098 |
|
| 7099 |
SeenAccessTypeInPath |= BaseNode == AccessType; |
7099 |
SeenAccessTypeInPath |= BaseNode == AccessType; |
| 7100 |
|
7100 |
|
| 7101 |
if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType) |
7101 |
if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType) |
| 7102 |
CheckTBAA(Offset == 0, "Offset not zero at the point of scalar access", |
7102 |
CheckTBAA(Offset == 0, "Offset not zero at the point of scalar access", |
| 7103 |
&I, MD, &Offset); |
7103 |
&I, MD, &Offset); |
| 7104 |
|
7104 |
|
| 7105 |
CheckTBAA(BaseNodeBitWidth == Offset.getBitWidth() || |
7105 |
CheckTBAA(BaseNodeBitWidth == Offset.getBitWidth() || |
| 7106 |
(BaseNodeBitWidth == 0 && Offset == 0) || |
7106 |
(BaseNodeBitWidth == 0 && Offset == 0) || |
| 7107 |
(IsNewFormat && BaseNodeBitWidth == ~0u), |
7107 |
(IsNewFormat && BaseNodeBitWidth == ~0u), |
| 7108 |
"Access bit-width not the same as description bit-width", &I, MD, |
7108 |
"Access bit-width not the same as description bit-width", &I, MD, |
| 7109 |
BaseNodeBitWidth, Offset.getBitWidth()); |
7109 |
BaseNodeBitWidth, Offset.getBitWidth()); |
| 7110 |
|
7110 |
|
| 7111 |
if (IsNewFormat && SeenAccessTypeInPath) |
7111 |
if (IsNewFormat && SeenAccessTypeInPath) |
| 7112 |
break; |
7112 |
break; |
| 7113 |
} |
7113 |
} |
| 7114 |
|
7114 |
|
| 7115 |
CheckTBAA(SeenAccessTypeInPath, "Did not see access type in access path!", &I, |
7115 |
CheckTBAA(SeenAccessTypeInPath, "Did not see access type in access path!", &I, |
| 7116 |
MD); |
7116 |
MD); |
| 7117 |
return true; |
7117 |
return true; |
| 7118 |
} |
7118 |
} |
| 7119 |
|
7119 |
|
| 7120 |
char VerifierLegacyPass::ID = 0; |
7120 |
char VerifierLegacyPass::ID = 0; |
| 7121 |
INITIALIZE_PASS(VerifierLegacyPass, "verify", "Module Verifier", false, false) |
7121 |
INITIALIZE_PASS(VerifierLegacyPass, "verify", "Module Verifier", false, false) |
| 7122 |
|
7122 |
|
| 7123 |
FunctionPass *llvm::createVerifierPass(bool FatalErrors) { |
7123 |
FunctionPass *llvm::createVerifierPass(bool FatalErrors) { |
| 7124 |
return new VerifierLegacyPass(FatalErrors); |
7124 |
return new VerifierLegacyPass(FatalErrors); |
| 7125 |
} |
7125 |
} |
| 7126 |
|
7126 |
|
| 7127 |
AnalysisKey VerifierAnalysis::Key; |
7127 |
AnalysisKey VerifierAnalysis::Key; |
| 7128 |
VerifierAnalysis::Result VerifierAnalysis::run(Module &M, |
7128 |
VerifierAnalysis::Result VerifierAnalysis::run(Module &M, |
| 7129 |
ModuleAnalysisManager &) { |
7129 |
ModuleAnalysisManager &) { |
| 7130 |
Result Res; |
7130 |
Result Res; |
| 7131 |
Res.IRBroken = llvm::verifyModule(M, &dbgs(), &Res.DebugInfoBroken); |
7131 |
Res.IRBroken = llvm::verifyModule(M, &dbgs(), &Res.DebugInfoBroken); |
| 7132 |
return Res; |
7132 |
return Res; |
| 7133 |
} |
7133 |
} |
| 7134 |
|
7134 |
|
| 7135 |
VerifierAnalysis::Result VerifierAnalysis::run(Function &F, |
7135 |
VerifierAnalysis::Result VerifierAnalysis::run(Function &F, |
| 7136 |
FunctionAnalysisManager &) { |
7136 |
FunctionAnalysisManager &) { |
| 7137 |
return { llvm::verifyFunction(F, &dbgs()), false }; |
7137 |
return { llvm::verifyFunction(F, &dbgs()), false }; |
| 7138 |
} |
7138 |
} |
| 7139 |
|
7139 |
|
| 7140 |
PreservedAnalyses VerifierPass::run(Module &M, ModuleAnalysisManager &AM) { |
7140 |
PreservedAnalyses VerifierPass::run(Module &M, ModuleAnalysisManager &AM) { |
| 7141 |
auto Res = AM.getResult(M); |
7141 |
auto Res = AM.getResult(M); |
| 7142 |
if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken)) |
7142 |
if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken)) |
| 7143 |
report_fatal_error("Broken module found, compilation aborted!"); |
7143 |
report_fatal_error("Broken module found, compilation aborted!"); |
| 7144 |
|
7144 |
|
| 7145 |
return PreservedAnalyses::all(); |
7145 |
return PreservedAnalyses::all(); |
| 7146 |
} |
7146 |
} |
| 7147 |
|
7147 |
|
| 7148 |
PreservedAnalyses VerifierPass::run(Function &F, FunctionAnalysisManager &AM) { |
7148 |
PreservedAnalyses VerifierPass::run(Function &F, FunctionAnalysisManager &AM) { |
| 7149 |
auto res = AM.getResult(F); |
7149 |
auto res = AM.getResult(F); |
| 7150 |
if (res.IRBroken && FatalErrors) |
7150 |
if (res.IRBroken && FatalErrors) |
| 7151 |
report_fatal_error("Broken function found, compilation aborted!"); |
7151 |
report_fatal_error("Broken function found, compilation aborted!"); |
| 7152 |
|
7152 |
|
| 7153 |
return PreservedAnalyses::all(); |
7153 |
return PreservedAnalyses::all(); |
| 7154 |
} |
7154 |
} |
| 7155 |
|
7155 |
|